You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Product.php 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 getQuantityTitle($productFamily)
  96. {
  97. $title = $this->getQuantityLabelInherited() ;
  98. if($productFamily->hasProductsWithVariousWeight()) {
  99. $title .= ', '.$this->getTitleInherited() ;
  100. }
  101. return $title ;
  102. }
  103. public function getAvailableQuantityInherited()
  104. {
  105. if($this->getProductFamily()->getBehaviorCountStock()) {
  106. return $this->getAvailableQuantity();
  107. }
  108. else {
  109. return $this->getProductFamily()->getAvailableQuantity();
  110. }
  111. }
  112. public function getTaxRateInherited()
  113. {
  114. return $this->getProductFamily()->getTaxRateInherited();
  115. }
  116. public function getProductFamily(): ?ProductFamily
  117. {
  118. return $this->productFamily;
  119. }
  120. public function setProductFamily(?ProductFamily $productFamily): self
  121. {
  122. $this->productFamily = $productFamily;
  123. return $this;
  124. }
  125. public function getTitle(): ?string
  126. {
  127. return $this->title;
  128. }
  129. public function setTitle(?string $title): self
  130. {
  131. $this->title = $title;
  132. return $this;
  133. }
  134. /**
  135. * @return Collection|OrderProductInterface[]
  136. */
  137. public function getOrderProducts(): Collection
  138. {
  139. return $this->orderProducts;
  140. }
  141. public function addOrderProduct(OrderProductInterface $orderProduct): self
  142. {
  143. if (!$this->orderProducts->contains($orderProduct)) {
  144. $this->orderProducts[] = $orderProduct;
  145. $orderProduct->setProduct($this);
  146. }
  147. return $this;
  148. }
  149. public function removeOrderProduct(OrderProductInterface $orderProduct): self
  150. {
  151. if ($this->orderProducts->contains($orderProduct)) {
  152. $this->orderProducts->removeElement($orderProduct);
  153. // set the owning side to null (unless already changed)
  154. if ($orderProduct->getProduct() === $this) {
  155. $orderProduct->setProduct(null);
  156. }
  157. }
  158. return $this;
  159. }
  160. }