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 4.4KB

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