Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Product.php 6.2KB

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