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.

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. }
  37. else {
  38. return $this->getProductFamily()->getBuyingPrice();
  39. }
  40. }
  41. public function getBuyingPriceByRefUnitInherited()
  42. {
  43. if($this->getBuyingPriceByRefUnit()) {
  44. return $this->getBuyingPriceByRefUnit();
  45. }
  46. else {
  47. return $this->getProductFamily()->getBuyingPriceByRefUnit();
  48. }
  49. }
  50. public function getPriceInherited()
  51. {
  52. if($this->getPrice()) {
  53. return $this->getPrice();
  54. }
  55. else {
  56. return $this->getProductFamily()->getPrice();
  57. }
  58. }
  59. public function getPriceByRefUnitInherited()
  60. {
  61. if($this->getPriceByRefUnit()) {
  62. return $this->getPriceByRefUnit();
  63. }
  64. else {
  65. return $this->getProductFamily()->getPriceByRefUnit();
  66. }
  67. }
  68. public function getBehaviorPriceInherited()
  69. {
  70. return $this->getProductFamily()->getBehaviorPrice() ;
  71. }
  72. public function getReductionCatalogInherited()
  73. {
  74. return $this->getProductFamily()->getReductionCatalog() ;
  75. }
  76. public function getUnitInherited()
  77. {
  78. if($this->getUnit()) {
  79. return $this->getUnit();
  80. }
  81. else {
  82. return $this->getProductFamily()->getUnit();
  83. }
  84. }
  85. public function getTitleInherited()
  86. {
  87. if($this->getTitle()){
  88. return $this->getTitle();
  89. }
  90. else{
  91. return $this->getProductFamily()->getTitle();
  92. }
  93. }
  94. public function getQuantityInherited()
  95. {
  96. if($this->getQuantity()) {
  97. return $this->getQuantity();
  98. }
  99. else{
  100. return $this->getProductFamily()->getQuantity();
  101. }
  102. }
  103. public function getQuantityLabelInherited()
  104. {
  105. $quantity = $this->getQuantityInherited() ;
  106. $unit = $this->getUnitInherited() ;
  107. return $quantity.$unit->getWordingShort() ;
  108. }
  109. public function getQuantityTitle($productFamily)
  110. {
  111. $title = $this->getQuantityLabelInherited() ;
  112. if($productFamily->hasProductsWithVariousWeight()) {
  113. $title .= ', '.$this->getTitleInherited() ;
  114. }
  115. return $title ;
  116. }
  117. public function getAvailableQuantityInherited()
  118. {
  119. if($this->getProductFamily()->getBehaviorCountStock()) {
  120. return $this->getAvailableQuantity();
  121. }
  122. else {
  123. return $this->getProductFamily()->getAvailableQuantity();
  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. }