您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. if ($this->getProductFamily()->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY ||
  113. $this->getProductFamily()->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
  114. return $this->getProductFamily()->getAvailableQuantity();
  115. } else if ($this->getProductFamily()->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT) {
  116. return $this->getAvailableQuantity();
  117. }
  118. }
  119. public function getTaxRateInherited()
  120. {
  121. return $this->getProductFamily()->getTaxRateInherited();
  122. }
  123. public function getProductFamily(): ?ProductFamily
  124. {
  125. return $this->productFamily;
  126. }
  127. public function setProductFamily(?ProductFamily $productFamily): self
  128. {
  129. $this->productFamily = $productFamily;
  130. return $this;
  131. }
  132. public function getTitle(): ?string
  133. {
  134. return $this->title;
  135. }
  136. public function setTitle(?string $title): self
  137. {
  138. $this->title = $title;
  139. return $this;
  140. }
  141. }