src/Entity/ECommerce/IndividualOrder.php line 172

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=[];
  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. public function setClosed($closed): self
  62. {
  63. $this->closed = $closed;
  64. return $this;
  65. }
  66. /**
  67. * Get closed
  68. *
  69. * @return boolean
  70. */
  71. public function getClosed()
  72. {
  73. return $this->closed;
  74. }
  75. /**
  76. * Set items
  77. *
  78. * @param array $items
  79. */
  80. public function setItems($items): self
  81. {
  82. $this->items = $items;
  83. return $this;
  84. }
  85. public function addItem(DepotProduct $product, int $quantity=1): void
  86. {
  87. $quantity = ($this->items[$product->getId()] ?? 0) + $quantity;
  88. $this->items[$product->getId()] = $quantity;
  89. }
  90. /**
  91. * @param int $quantity
  92. */
  93. public function removeItem(DepotProduct $product): void
  94. {
  95. unset($this->items[$product->getId()]);
  96. }
  97. /**
  98. * Get items
  99. *
  100. * @return array
  101. */
  102. public function getItems()
  103. {
  104. return $this->items;
  105. }
  106. public function getQuantity(DepotProduct $depotProduct): int
  107. {
  108. return $this->items[$depotProduct->getId()] ?? 0;
  109. }
  110. /**
  111. * @return int
  112. */
  113. public function setQuantity(DepotProduct $depotProduct): self
  114. {
  115. $this->items[$depotProduct->getId()] = $depotProduct->getQuantity();
  116. return $this;
  117. }
  118. public function countItems(): float
  119. {
  120. return array_sum($this->items);
  121. }
  122. /**
  123. * Set notes.
  124. *
  125. * @param string|null $notes
  126. */
  127. public function setNotes($notes = null): static
  128. {
  129. $this->notes = $notes;
  130. return $this;
  131. }
  132. /**
  133. * Get notes.
  134. *
  135. * @return string|null
  136. */
  137. public function getNotes()
  138. {
  139. return $this->notes;
  140. }
  141. /**
  142. * Set user
  143. *
  144. *
  145. */
  146. public function setUser(User $user = null): self
  147. {
  148. $this->user = $user;
  149. return $this;
  150. }
  151. /**
  152. * Get user
  153. *
  154. * @return User
  155. */
  156. public function getUser()
  157. {
  158. return $this->user;
  159. }
  160. }