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.

191 lines
5.9KB

  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. use Gedmo\Mapping\Annotation as Gedmo;
  13. /**
  14. * @ORM\MappedSuperclass()
  15. */
  16. abstract class Product extends AbstractEntity implements SortableInterface, ProductPropertyInterface, PriceInterface
  17. {
  18. use SortableTrait;
  19. use ProductPropertyTrait;
  20. use StatusTrait;
  21. /**
  22. * @Gedmo\Blameable(on="create")
  23. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface")
  24. * @ORM\JoinColumn(nullable=true)
  25. */
  26. protected $createdBy;
  27. /**
  28. * @Gedmo\Blameable(on="update")
  29. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface")
  30. * @ORM\JoinColumn(nullable=true)
  31. */
  32. protected $updatedBy;
  33. /**
  34. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\ProductFamilyInterface", inversedBy="products")
  35. * @ORM\JoinColumn(nullable=false)
  36. */
  37. protected $productFamily;
  38. /**
  39. * @ORM\Column(type="string", length=255, nullable=true)
  40. */
  41. protected $title;
  42. public function __construct()
  43. {
  44. $this->orderProducts = new ArrayCollection();
  45. }
  46. public function getBuyingPriceInherited()
  47. {
  48. if ($this->getBuyingPrice()) {
  49. return $this->getBuyingPrice();
  50. } else {
  51. return $this->getProductFamily()->getBuyingPrice();
  52. }
  53. }
  54. public function getBuyingPriceByRefUnitInherited()
  55. {
  56. if ($this->getBuyingPriceByRefUnit()) {
  57. return $this->getBuyingPriceByRefUnit();
  58. } else {
  59. return $this->getProductFamily()->getBuyingPriceByRefUnit();
  60. }
  61. }
  62. public function getPriceInherited()
  63. {
  64. if ($this->getPrice()) {
  65. return $this->getPrice();
  66. } else {
  67. return $this->getProductFamily()->getPrice();
  68. }
  69. }
  70. public function getPriceByRefUnitInherited()
  71. {
  72. if ($this->getPriceByRefUnit()) {
  73. return $this->getPriceByRefUnit();
  74. } else {
  75. return $this->getProductFamily()->getPriceByRefUnit();
  76. }
  77. }
  78. public function getBehaviorPriceInherited()
  79. {
  80. return $this->getProductFamily()->getBehaviorPrice();
  81. }
  82. public function getReductionCatalogInherited()
  83. {
  84. return $this->getProductFamily()->getReductionCatalog();
  85. }
  86. public function getUnitInherited()
  87. {
  88. if ($this->getUnit()) {
  89. return $this->getUnit();
  90. } else {
  91. return $this->getProductFamily()->getUnit();
  92. }
  93. }
  94. public function getTitleInherited()
  95. {
  96. if ($this->getTitle()) {
  97. return $this->getTitle();
  98. } else {
  99. return $this->getProductFamily()->getTitle();
  100. }
  101. }
  102. public function getQuantityInherited()
  103. {
  104. if ($this->getQuantity()) {
  105. return $this->getQuantity();
  106. }
  107. else {
  108. return $this->getProductFamily()->getQuantity();
  109. }
  110. }
  111. public function getQuantityLabelInherited()
  112. {
  113. $quantity = $this->getQuantityInherited();
  114. $unit = $this->getUnitInherited();
  115. return $quantity . $unit->getWordingShort();
  116. }
  117. public function getQuantityTitle($productFamily)
  118. {
  119. $title = $this->getQuantityLabelInherited();
  120. if ($productFamily->hasProductsWithVariousWeight()) {
  121. $title .= ', ' . $this->getTitleInherited();
  122. }
  123. return $title;
  124. }
  125. public function getAvailableQuantityInherited()
  126. {
  127. switch ($this->getProductFamily()->getBehaviorCountStock()) {
  128. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  129. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  130. return $this->getProductFamily()->getAvailableQuantity();
  131. break;
  132. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  133. return $this->getAvailableQuantity();
  134. break;
  135. case ProductFamily::BEHAVIOR_COUNT_STOCK_UNLIMITED :
  136. return false;
  137. break;
  138. }
  139. }
  140. public function getTaxRateInherited()
  141. {
  142. return $this->getProductFamily()->getTaxRateInherited();
  143. }
  144. public function getProductFamily(): ?ProductFamily
  145. {
  146. return $this->productFamily;
  147. }
  148. public function setProductFamily(?ProductFamily $productFamily): self
  149. {
  150. $this->productFamily = $productFamily;
  151. return $this;
  152. }
  153. public function getTitle(): ?string
  154. {
  155. return $this->title;
  156. }
  157. public function setTitle(?string $title): self
  158. {
  159. $this->title = $title;
  160. return $this;
  161. }
  162. }