Product.php 5.9KB

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