<?php
namespace App\Entity\ECommerce;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\App\User;
/**
* IndividualOrder
*
* @ORM\Table(name="individual_order")
* @ORM\Entity(repositoryClass="App\Repository\ECommerce\IndividualOrderRepository")
* @ORM\Cache(usage="READ_ONLY", region="private")
*/
class IndividualOrder
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var boolean
*
* @ORM\Column(name="closed", type="boolean", nullable=true)
*/
protected $closed=false;
/**
* @var array
*
* @ORM\Column(name="items", type="json", nullable=true)
*/
protected $items=array();
/**
* @var string
* @ORM\Column(name="notes", type="text", nullable=true)
*/
protected $notes;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="App\Entity\App\User", inversedBy="orders", cascade={"persist"})
*/
protected $user;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set closed
*
* @param boolean $closed
*
* @return IndividualOrder
*/
public function setClosed($closed): self
{
$this->closed = $closed;
return $this;
}
/**
* Get closed
*
* @return boolean
*/
public function getClosed()
{
return $this->closed;
}
/**
* Set items
*
* @param array $items
*
* @return IndividualOrder
*/
public function setItems($items): self
{
$this->items = $items;
return $this;
}
/**
* @param DepotProduct $product
* @param int $quantity
*/
public function addItem(DepotProduct $product, int $quantity=1)
{
$quantity = ($this->items[$product->getId()] ?? 0) + $quantity;
$this->items[$product->getId()] = $quantity;
}
/**
* @param DepotProduct $product
* @param int $quantity
*/
public function removeItem(DepotProduct $product)
{
unset($this->items[$product->getId()]);
}
/**
* Get items
*
* @return array
*/
public function getItems()
{
return $this->items;
}
/**
* @param DepotProduct $depotProduct
*
* @return int
*/
public function getQuantity(DepotProduct $depotProduct): int
{
return $this->items[$depotProduct->getId()] ?? 0;
}
/**
* @param DepotProduct $depotProduct
*
* @return int
*/
public function setQuantity(DepotProduct $depotProduct): self
{
$this->items[$depotProduct->getId()] = $depotProduct->getQuantity();
return $this;
}
/**
* @return float
*/
public function countItems(): float
{
return array_sum($this->items);
}
/**
* Set notes.
*
* @param string|null $notes
*
* @return IndividualOrder
*/
public function setNotes($notes = null)
{
$this->notes = $notes;
return $this;
}
/**
* Get notes.
*
* @return string|null
*/
public function getNotes()
{
return $this->notes;
}
/**
* Set user
*
* @param User $user
*
* @return IndividualOrder
*/
public function setUser(User $user = null): self
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return User
*/
public function getUser()
{
return $this->user;
}
}