src/Entity/ECommerce/IndividualOrder.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\ECommerce;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use App\Entity\App\User;
  7. /**
  8. * IndividualOrder
  9. *
  10. * @ORM\Table(name="individual_order")
  11. * @ORM\Entity(repositoryClass="App\Repository\ECommerce\IndividualOrderRepository")
  12. * @ORM\Cache(usage="READ_ONLY", region="private")
  13. */
  14. class IndividualOrder
  15. {
  16. /**
  17. * @var int
  18. *
  19. * @ORM\Column(name="id", type="integer")
  20. * @ORM\Id
  21. * @ORM\GeneratedValue(strategy="AUTO")
  22. */
  23. private $id;
  24. /**
  25. * @var boolean
  26. *
  27. * @ORM\Column(name="closed", type="boolean", nullable=true)
  28. */
  29. protected $closed=false;
  30. /**
  31. * @var array
  32. *
  33. * @ORM\Column(name="items", type="json", nullable=true)
  34. */
  35. protected $items=array();
  36. /**
  37. * @var string
  38. * @ORM\Column(name="notes", type="text", nullable=true)
  39. */
  40. protected $notes;
  41. /**
  42. * @var User
  43. *
  44. * @ORM\ManyToOne(targetEntity="App\Entity\App\User", inversedBy="orders", cascade={"persist"})
  45. */
  46. protected $user;
  47. /**
  48. * Get id
  49. *
  50. * @return int
  51. */
  52. public function getId()
  53. {
  54. return $this->id;
  55. }
  56. /**
  57. * Set closed
  58. *
  59. * @param boolean $closed
  60. *
  61. * @return IndividualOrder
  62. */
  63. public function setClosed($closed): self
  64. {
  65. $this->closed = $closed;
  66. return $this;
  67. }
  68. /**
  69. * Get closed
  70. *
  71. * @return boolean
  72. */
  73. public function getClosed()
  74. {
  75. return $this->closed;
  76. }
  77. /**
  78. * Set items
  79. *
  80. * @param array $items
  81. *
  82. * @return IndividualOrder
  83. */
  84. public function setItems($items): self
  85. {
  86. $this->items = $items;
  87. return $this;
  88. }
  89. /**
  90. * @param DepotProduct $product
  91. * @param int $quantity
  92. */
  93. public function addItem(DepotProduct $product, int $quantity=1)
  94. {
  95. $quantity = ($this->items[$product->getId()] ?? 0) + $quantity;
  96. $this->items[$product->getId()] = $quantity;
  97. }
  98. /**
  99. * @param DepotProduct $product
  100. * @param int $quantity
  101. */
  102. public function removeItem(DepotProduct $product)
  103. {
  104. unset($this->items[$product->getId()]);
  105. }
  106. /**
  107. * Get items
  108. *
  109. * @return array
  110. */
  111. public function getItems()
  112. {
  113. return $this->items;
  114. }
  115. /**
  116. * @param DepotProduct $depotProduct
  117. *
  118. * @return int
  119. */
  120. public function getQuantity(DepotProduct $depotProduct): int
  121. {
  122. return $this->items[$depotProduct->getId()] ?? 0;
  123. }
  124. /**
  125. * @param DepotProduct $depotProduct
  126. *
  127. * @return int
  128. */
  129. public function setQuantity(DepotProduct $depotProduct): self
  130. {
  131. $this->items[$depotProduct->getId()] = $depotProduct->getQuantity();
  132. return $this;
  133. }
  134. /**
  135. * @return float
  136. */
  137. public function countItems(): float
  138. {
  139. return array_sum($this->items);
  140. }
  141. /**
  142. * Set notes.
  143. *
  144. * @param string|null $notes
  145. *
  146. * @return IndividualOrder
  147. */
  148. public function setNotes($notes = null)
  149. {
  150. $this->notes = $notes;
  151. return $this;
  152. }
  153. /**
  154. * Get notes.
  155. *
  156. * @return string|null
  157. */
  158. public function getNotes()
  159. {
  160. return $this->notes;
  161. }
  162. /**
  163. * Set user
  164. *
  165. * @param User $user
  166. *
  167. * @return IndividualOrder
  168. */
  169. public function setUser(User $user = null): self
  170. {
  171. $this->user = $user;
  172. return $this;
  173. }
  174. /**
  175. * Get user
  176. *
  177. * @return User
  178. */
  179. public function getUser()
  180. {
  181. return $this->user;
  182. }
  183. }