181 行
5.3KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Lc\ShopBundle\Context\OrderProductInterface;
  7. use Lc\ShopBundle\Context\PriceInterface;
  8. use Lc\ShopBundle\Context\ProductInterface;
  9. use Lc\ShopBundle\Context\ProductPropertyInterface;
  10. use Lc\ShopBundle\Context\SortableInterface;
  11. use Lc\ShopBundle\Services\Price;
  12. /**
  13. * @ORM\MappedSuperclass()
  14. */
  15. abstract class Product extends AbstractEntity implements SortableInterface, ProductPropertyInterface, PriceInterface
  16. {
  17. use SortableTrait;
  18. use ProductPropertyTrait;
  19. /**
  20. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\ProductFamilyInterface", inversedBy="products")
  21. * @ORM\JoinColumn(nullable=false)
  22. */
  23. protected $productFamily;
  24. /**
  25. * @ORM\Column(type="string", length=255, nullable=true)
  26. */
  27. protected $title;
  28. /**
  29. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderProductInterface", mappedBy="product", orphanRemoval=true, cascade={"remove"})
  30. */
  31. protected $orderProducts ;
  32. public function __construct()
  33. {
  34. $this->orderProducts = new ArrayCollection() ;
  35. }
  36. public function getPriceInherited()
  37. {
  38. if($this->getPrice()) {
  39. return $this->getPrice();
  40. }
  41. else {
  42. return $this->getProductFamily()->getPrice();
  43. }
  44. }
  45. public function getPriceByRefUnitInherited()
  46. {
  47. if($this->getPriceByRefUnit()) {
  48. return $this->getPriceByRefUnit();
  49. }
  50. else {
  51. return $this->getProductFamily()->getPriceByRefUnit();
  52. }
  53. }
  54. public function getBehaviorPriceInherited()
  55. {
  56. return $this->getProductFamily()->getBehaviorPrice() ;
  57. }
  58. public function getReductionCatalogInherited()
  59. {
  60. return $this->getProductFamily()->getReductionCatalog() ;
  61. }
  62. public function getUnitInherited()
  63. {
  64. if($this->getUnit()) {
  65. return $this->getUnit();
  66. }
  67. else {
  68. return $this->getProductFamily()->getUnit();
  69. }
  70. }
  71. public function getTitleInherited()
  72. {
  73. if($this->getTitle()){
  74. return $this->getTitle();
  75. }
  76. else{
  77. return $this->getProductFamily()->getTitle();
  78. }
  79. }
  80. public function getQuantityInherited()
  81. {
  82. if($this->getQuantity()) {
  83. return $this->getQuantity();
  84. }
  85. else{
  86. return $this->getProductFamily()->getQuantity();
  87. }
  88. }
  89. public function getQuantityLabelInherited()
  90. {
  91. $quantity = $this->getQuantityInherited() ;
  92. $unit = $this->getUnitInherited() ;
  93. return $quantity.$unit->getWordingShort() ;
  94. }
  95. public function getAvailableQuantityInherited()
  96. {
  97. if($this->getProductFamily()->getBehaviorCountStock()) {
  98. return $this->getAvailableQuantity();
  99. }
  100. else {
  101. return $this->getProductFamily()->getAvailableQuantity();
  102. }
  103. }
  104. public function getTaxRateInherited()
  105. {
  106. return $this->getProductFamily()->getTaxRateInherited();
  107. }
  108. public function getProductFamily(): ?ProductFamily
  109. {
  110. return $this->productFamily;
  111. }
  112. public function setProductFamily(?ProductFamily $productFamily): self
  113. {
  114. $this->productFamily = $productFamily;
  115. return $this;
  116. }
  117. public function getTitle(): ?string
  118. {
  119. return $this->title;
  120. }
  121. public function setTitle(?string $title): self
  122. {
  123. $this->title = $title;
  124. return $this;
  125. }
  126. /**
  127. * @return Collection|OrderProductInterface[]
  128. */
  129. public function getOrderProducts(): Collection
  130. {
  131. return $this->orderProducts;
  132. }
  133. public function addOrderProduct(OrderProductInterface $orderProduct): self
  134. {
  135. if (!$this->orderProducts->contains($orderProduct)) {
  136. $this->orderProducts[] = $orderProduct;
  137. $orderProduct->setProduct($this);
  138. }
  139. return $this;
  140. }
  141. public function removeOrderProduct(OrderProductInterface $orderProduct): self
  142. {
  143. if ($this->orderProducts->contains($orderProduct)) {
  144. $this->orderProducts->removeElement($orderProduct);
  145. // set the owning side to null (unless already changed)
  146. if ($orderProduct->getProduct() === $this) {
  147. $orderProduct->setProduct(null);
  148. }
  149. }
  150. return $this;
  151. }
  152. }