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.

166 lines
4.8KB

  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->price) {
  39. return $this->price;
  40. }
  41. else {
  42. return $this->productFamily->getPrice();
  43. }
  44. }
  45. public function getUnitInherited()
  46. {
  47. if($this->unit) {
  48. return $this->unit;
  49. }
  50. else{
  51. return $this->productFamily->getUnit();
  52. }
  53. }
  54. public function getTitleInherited()
  55. {
  56. if($this->title){
  57. return $this->title;
  58. }
  59. else{
  60. return $this->productFamily->getTitle();
  61. }
  62. }
  63. public function getQuantityInherited()
  64. {
  65. if($this->quantity) {
  66. return $this->quantity;
  67. }
  68. else{
  69. return $this->productFamily->getQuantity();
  70. }
  71. }
  72. public function getQuantityLabelInherited()
  73. {
  74. $quantity = $this->getQuantityInherited() ;
  75. $unit = $this->getUnitInherited() ;
  76. return $quantity.$unit->getWordingShort() ;
  77. }
  78. public function getAvailableQuantityInherited()
  79. {
  80. if($this->productFamily->getBehaviorCountStock()) {
  81. return $this->availableQuantity;
  82. }
  83. else{
  84. return $this->productFamily->getAvailableQuantity();
  85. }
  86. }
  87. public function getTaxRateInherited()
  88. {
  89. if($this->productFamily->getTaxRate()) {
  90. return $this->productFamily->getTaxRate();
  91. }
  92. else{
  93. return $this->productFamily->getMerchant()->getTaxRate()->getValue();
  94. }
  95. }
  96. public function getProductFamily(): ?ProductFamily
  97. {
  98. return $this->productFamily;
  99. }
  100. public function setProductFamily(?ProductFamily $productFamily): self
  101. {
  102. $this->productFamily = $productFamily;
  103. return $this;
  104. }
  105. public function getTitle(): ?string
  106. {
  107. return $this->title;
  108. }
  109. public function setTitle(?string $title): self
  110. {
  111. $this->title = $title;
  112. return $this;
  113. }
  114. /**
  115. * @return Collection|OrderProductInterface[]
  116. */
  117. public function getOrderProducts(): Collection
  118. {
  119. return $this->orderProducts;
  120. }
  121. public function addOrderProduct(OrderProductInterface $orderProduct): self
  122. {
  123. if (!$this->orderProducts->contains($orderProduct)) {
  124. $this->orderProducts[] = $orderProduct;
  125. $orderProduct->setProduct($this);
  126. }
  127. return $this;
  128. }
  129. public function removeOrderProduct(OrderProductInterface $orderProduct): self
  130. {
  131. if ($this->orderProducts->contains($orderProduct)) {
  132. $this->orderProducts->removeElement($orderProduct);
  133. // set the owning side to null (unless already changed)
  134. if ($orderProduct->getProduct() === $this) {
  135. $orderProduct->setProduct(null);
  136. }
  137. }
  138. return $this;
  139. }
  140. }