Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

174 lines
5.4KB

  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. public function __construct()
  29. {
  30. $this->orderProducts = new ArrayCollection();
  31. }
  32. public function getBuyingPriceInherited()
  33. {
  34. if ($this->getBuyingPrice()) {
  35. return $this->getBuyingPrice();
  36. } else {
  37. return $this->getProductFamily()->getBuyingPrice();
  38. }
  39. }
  40. public function getBuyingPriceByRefUnitInherited()
  41. {
  42. if ($this->getBuyingPriceByRefUnit()) {
  43. return $this->getBuyingPriceByRefUnit();
  44. } else {
  45. return $this->getProductFamily()->getBuyingPriceByRefUnit();
  46. }
  47. }
  48. public function getPriceInherited()
  49. {
  50. if ($this->getPrice()) {
  51. return $this->getPrice();
  52. } else {
  53. return $this->getProductFamily()->getPrice();
  54. }
  55. }
  56. public function getPriceByRefUnitInherited()
  57. {
  58. if ($this->getPriceByRefUnit()) {
  59. return $this->getPriceByRefUnit();
  60. } else {
  61. return $this->getProductFamily()->getPriceByRefUnit();
  62. }
  63. }
  64. public function getBehaviorPriceInherited()
  65. {
  66. return $this->getProductFamily()->getBehaviorPrice();
  67. }
  68. public function getReductionCatalogInherited()
  69. {
  70. return $this->getProductFamily()->getReductionCatalog();
  71. }
  72. public function getUnitInherited()
  73. {
  74. if ($this->getUnit()) {
  75. return $this->getUnit();
  76. } else {
  77. return $this->getProductFamily()->getUnit();
  78. }
  79. }
  80. public function getTitleInherited()
  81. {
  82. if ($this->getTitle()) {
  83. return $this->getTitle();
  84. } else {
  85. return $this->getProductFamily()->getTitle();
  86. }
  87. }
  88. public function getQuantityInherited()
  89. {
  90. if ($this->getQuantity()) {
  91. return $this->getQuantity();
  92. } else {
  93. return $this->getProductFamily()->getQuantity();
  94. }
  95. }
  96. public function getQuantityLabelInherited()
  97. {
  98. $quantity = $this->getQuantityInherited();
  99. $unit = $this->getUnitInherited();
  100. return $quantity . $unit->getWordingShort();
  101. }
  102. public function getQuantityTitle($productFamily)
  103. {
  104. $title = $this->getQuantityLabelInherited();
  105. if ($productFamily->hasProductsWithVariousWeight()) {
  106. $title .= ', ' . $this->getTitleInherited();
  107. }
  108. return $title;
  109. }
  110. public function getAvailableQuantityInherited()
  111. {
  112. switch ($this->getProductFamily()->getBehaviorCountStock()) {
  113. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  114. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  115. return $this->getProductFamily()->getAvailableQuantity();
  116. break;
  117. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  118. return $this->getAvailableQuantity();
  119. break;
  120. case ProductFamily::BEHAVIOR_COUNT_STOCK_UNLIMITED :
  121. return false;
  122. break;
  123. }
  124. }
  125. public function getTaxRateInherited()
  126. {
  127. return $this->getProductFamily()->getTaxRateInherited();
  128. }
  129. public function getProductFamily(): ?ProductFamily
  130. {
  131. return $this->productFamily;
  132. }
  133. public function setProductFamily(?ProductFamily $productFamily): self
  134. {
  135. $this->productFamily = $productFamily;
  136. return $this;
  137. }
  138. public function getTitle(): ?string
  139. {
  140. return $this->title;
  141. }
  142. public function setTitle(?string $title): self
  143. {
  144. $this->title = $title;
  145. return $this;
  146. }
  147. }