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.

Product.php 5.4KB

4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
4 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. }
  93. else {
  94. return $this->getProductFamily()->getQuantity();
  95. }
  96. }
  97. public function getQuantityLabelInherited()
  98. {
  99. $quantity = $this->getQuantityInherited();
  100. $unit = $this->getUnitInherited();
  101. return $quantity . $unit->getWordingShort();
  102. }
  103. public function getQuantityTitle($productFamily)
  104. {
  105. $title = $this->getQuantityLabelInherited();
  106. if ($productFamily->hasProductsWithVariousWeight()) {
  107. $title .= ', ' . $this->getTitleInherited();
  108. }
  109. return $title;
  110. }
  111. public function getAvailableQuantityInherited()
  112. {
  113. switch ($this->getProductFamily()->getBehaviorCountStock()) {
  114. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  115. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  116. return $this->getProductFamily()->getAvailableQuantity();
  117. break;
  118. case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  119. return $this->getAvailableQuantity();
  120. break;
  121. case ProductFamily::BEHAVIOR_COUNT_STOCK_UNLIMITED :
  122. return false;
  123. break;
  124. }
  125. }
  126. public function getTaxRateInherited()
  127. {
  128. return $this->getProductFamily()->getTaxRateInherited();
  129. }
  130. public function getProductFamily(): ?ProductFamily
  131. {
  132. return $this->productFamily;
  133. }
  134. public function setProductFamily(?ProductFamily $productFamily): self
  135. {
  136. $this->productFamily = $productFamily;
  137. return $this;
  138. }
  139. public function getTitle(): ?string
  140. {
  141. return $this->title;
  142. }
  143. public function setTitle(?string $title): self
  144. {
  145. $this->title = $title;
  146. return $this;
  147. }
  148. }