src/Entity/ECommerce/DepotProduct.php line 227

Open in your IDE?
  1. <?php
  2. namespace App\Entity\ECommerce;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Entity\ECommerce\Traits\DatesTrait;
  5. use JMS\Serializer\Annotation as JMS;
  6. use Stringable;
  7. /**
  8. * DepotProduct
  9. *
  10. * @ORM\Table(name="depot_product")
  11. * @ORM\Entity(repositoryClass="App\Repository\ECommerce\DepotProductRepository")
  12. * @ORM\HasLifecycleCallbacks()
  13. */
  14. class DepotProduct implements Stringable
  15. {
  16. /**
  17. * @ORM\Column(name="id", type="integer")
  18. * @ORM\Id
  19. * @ORM\GeneratedValue(strategy="AUTO")
  20. *
  21. * @JMS\Groups({"depot_product_private", "view_depot_product"})
  22. */
  23. private int $id;
  24. /**
  25. * @ORM\Column(name="remote_id", type="string", nullable=true)
  26. *
  27. * @JMS\Groups({"depot_product_private", "view_depot_product"})
  28. */
  29. private ?string $remoteId = null;
  30. /**
  31. * @ORM\Column(name="quantity", type="integer")
  32. *
  33. * @JMS\Groups({"depot_product_private", "view_depot_product"})
  34. */
  35. private int $quantity = 0;
  36. /**
  37. * @ORM\Column(name="minimal_quantity", type="integer")
  38. *
  39. * @JMS\Groups({"depot_product_private", "view_depot_product"})
  40. */
  41. private ?int $minimalQuantity = null;
  42. /**
  43. * @ORM\Column(name="optimal_quantity", type="integer")
  44. *
  45. * @JMS\Groups({"depot_product_private", "view_depot_product"})
  46. */
  47. private ?int $optimalQuantity = null;
  48. /**
  49. * @ORM\Column(name="price", type="float", nullable=false)
  50. */
  51. private float $price = 0;
  52. /**
  53. * @ORM\Column(name="tax_rate", type="decimal", precision=10, scale=0)
  54. */
  55. private string|float $taxRate = 0;
  56. /**
  57. * @ORM\Column(name="location", type="string", length=90, nullable=true)
  58. */
  59. protected string $location;
  60. /**
  61. * @ORM\ManyToOne(targetEntity="App\Entity\ECommerce\Product", inversedBy="quantities")
  62. * @ORM\JoinColumn(name="product", referencedColumnName="id")
  63. *
  64. * @JMS\Groups({"depot_product_private", "view_depot_product"})
  65. */
  66. private ?Product $product = null;
  67. /**
  68. * @ORM\ManyToOne(targetEntity="App\Entity\ECommerce\Depot", inversedBy="products")
  69. * @ORM\JoinColumn(name="depot", referencedColumnName="id")
  70. */
  71. private ?Depot $depot = null;
  72. use DatesTrait {
  73. DatesTrait::__construct as __DTConstruct;
  74. }
  75. public function __construct()
  76. {
  77. $this->__DTConstruct();
  78. }
  79. public function __toString(): string
  80. {
  81. return (string)$this->id;
  82. }
  83. public function getId(): ?int
  84. {
  85. return $this->id;
  86. }
  87. public function setRemoteId(?string $remoteId = null): self
  88. {
  89. $this->remoteId = $remoteId;
  90. return $this;
  91. }
  92. public function getRemoteId(): ?string
  93. {
  94. return $this->remoteId;
  95. }
  96. public function setQuantity(int $quantity = 0): self
  97. {
  98. $this->quantity = $quantity;
  99. return $this;
  100. }
  101. public function getQuantity(): int
  102. {
  103. return $this->quantity;
  104. }
  105. public function incrementQuantity(): int
  106. {
  107. return $this->quantity++;
  108. }
  109. public function decrementQuantity(): int
  110. {
  111. --$this->quantity;
  112. if ($this->quantity < 0) {
  113. $this->quantity = 0;
  114. }
  115. return $this->quantity;
  116. }
  117. public function setMinimalQuantity(?int $minimalQuantity): self
  118. {
  119. $this->minimalQuantity = $minimalQuantity;
  120. return $this;
  121. }
  122. public function getMinimalQuantity(): ?int
  123. {
  124. return $this->minimalQuantity;
  125. }
  126. public function setOptimalQuantity(?int $optimalQuantity): self
  127. {
  128. $this->optimalQuantity = $optimalQuantity;
  129. return $this;
  130. }
  131. public function getOptimalQuantity(): ?int
  132. {
  133. return $this->optimalQuantity;
  134. }
  135. public function setPrice(float $price): self
  136. {
  137. $this->price = $price;
  138. return $this;
  139. }
  140. public function getPrice(): ?float
  141. {
  142. return $this->price;
  143. }
  144. public function setTaxRate(float $taxRate): self
  145. {
  146. $this->taxRate = $taxRate;
  147. return $this;
  148. }
  149. public function getTaxRate(): ?float
  150. {
  151. if (!$this->taxRate) {
  152. return 0.0;
  153. }
  154. return (float)$this->taxRate;
  155. }
  156. public function getTaxRateMultiplier(): float
  157. {
  158. return $this->getTaxRate() * 0.01;
  159. }
  160. public function setLocation(string $location): self
  161. {
  162. $this->location = $location;
  163. return $this;
  164. }
  165. public function getLocation(): ?string
  166. {
  167. return $this->location;
  168. }
  169. public function setProduct(Product $product = null): self
  170. {
  171. $product?->addQuantity($this);
  172. $this->product = $product;
  173. return $this;
  174. }
  175. public function getProduct(): ?Product
  176. {
  177. return $this->product;
  178. }
  179. public function setDepot(Depot $depot = null): self
  180. {
  181. if($depot instanceof \App\Entity\ECommerce\Depot) {
  182. $this->depot = $depot->addProduct($this);
  183. }
  184. return $this;
  185. }
  186. public function getDepot(): ?Depot
  187. {
  188. return $this->depot;
  189. }
  190. /**
  191. * @ORM\PostLoad()
  192. */
  193. public function onLoad(): void
  194. {
  195. if ($this->getQuantity() < 0) {
  196. $this->setQuantity(0);
  197. }
  198. }
  199. }