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.

ProductModel.php 5.9KB

3 yıl önce
3 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. namespace Lc\CaracoleBundle\Model\Product;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyTrait;
  6. use Lc\CaracoleBundle\Doctrine\Extension\PriceInterface;
  7. use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use Lc\SovBundle\Doctrine\Extension\SortableInterface;
  10. use Lc\SovBundle\Doctrine\Extension\SortableTrait;
  11. use Lc\SovBundle\Doctrine\Extension\StatusTrait;
  12. use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
  13. /**
  14. * @ORM\MappedSuperclass()
  15. */
  16. abstract class ProductModel extends AbstractLightEntity implements SortableInterface, ProductPropertyInterface,
  17. PriceInterface
  18. {
  19. use SortableTrait;
  20. use ProductPropertyTrait;
  21. use StatusTrait;
  22. /**
  23. * @Gedmo\Blameable(on="create")
  24. * @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface")
  25. * @ORM\JoinColumn(nullable=true)
  26. */
  27. protected $createdBy;
  28. /**
  29. * @Gedmo\Blameable(on="update")
  30. * @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface")
  31. * @ORM\JoinColumn(nullable=true)
  32. */
  33. protected $updatedBy;
  34. /**
  35. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Product\ProductFamilyInterface", inversedBy="products", cascade={"persist"})
  36. * @ORM\JoinColumn(nullable=false)
  37. */
  38. protected $productFamily;
  39. /**
  40. * @ORM\Column(type="string", length=255, nullable=true)
  41. */
  42. protected $title;
  43. /**
  44. * @ORM\Column(type="boolean", nullable=true)
  45. */
  46. protected $originProduct;
  47. public function __construct()
  48. {
  49. $this->orderProducts = new ArrayCollection();
  50. $this->status = 1;
  51. }
  52. public function __toString()
  53. {
  54. $title = $this->getProductFamily()->getTitle();
  55. if ($this->getTitle() && strlen($this->getTitle())) {
  56. $title .= ' - ' . $this->getTitle();
  57. }
  58. if ($this->getProductFamily()->hasProductsWithVariousWeight()) {
  59. $title .= ' - ' . $this->getQuantityLabelInherited();
  60. }
  61. return $title;
  62. }
  63. public function getBuyingPriceInherited()
  64. {
  65. if ($this->getBuyingPrice()) {
  66. return $this->getBuyingPrice();
  67. } else {
  68. return $this->getProductFamily()->getBuyingPrice();
  69. }
  70. }
  71. public function getBuyingPriceByRefUnitInherited()
  72. {
  73. if ($this->getBuyingPriceByRefUnit()) {
  74. return $this->getBuyingPriceByRefUnit();
  75. } else {
  76. return $this->getProductFamily()->getBuyingPriceByRefUnit();
  77. }
  78. }
  79. public function getPriceInherited()
  80. {
  81. if ($this->getPrice()) {
  82. return $this->getPrice();
  83. } else {
  84. return $this->getProductFamily()->getPrice();
  85. }
  86. }
  87. public function getPriceByRefUnitInherited()
  88. {
  89. if ($this->getPriceByRefUnit()) {
  90. return $this->getPriceByRefUnit();
  91. } else {
  92. return $this->getProductFamily()->getPriceByRefUnit();
  93. }
  94. }
  95. public function getBehaviorPriceInherited()
  96. {
  97. return $this->getProductFamily()->getBehaviorPrice();
  98. }
  99. public function getReductionCatalogInherited()
  100. {
  101. return $this->getProductFamily()->getReductionCatalog();
  102. }
  103. public function getUnitInherited()
  104. {
  105. if ($this->getUnit()) {
  106. return $this->getUnit();
  107. } else {
  108. return $this->getProductFamily()->getUnit();
  109. }
  110. }
  111. public function getTitleInherited()
  112. {
  113. if ($this->getTitle()) {
  114. return $this->getTitle();
  115. } else {
  116. return $this->getProductFamily()->getTitle();
  117. }
  118. }
  119. public function getQuantityInherited()
  120. {
  121. if ($this->getQuantity()) {
  122. return $this->getQuantity();
  123. } else {
  124. return $this->getProductFamily()->getQuantity();
  125. }
  126. }
  127. public function getQuantityLabelInherited()
  128. {
  129. $quantity = $this->getQuantityInherited();
  130. $unit = $this->getUnitInherited();
  131. return $quantity . $unit->getWordingShort();
  132. }
  133. public function getQuantityTitle($productFamily)
  134. {
  135. $title = $this->getQuantityLabelInherited();
  136. if ($productFamily->hasProductsWithVariousWeight()) {
  137. $title .= ', ' . $this->getTitleInherited();
  138. }
  139. return $title;
  140. }
  141. public function getAvailableQuantityInherited()
  142. {
  143. switch ($this->getProductFamily()->getBehaviorCountStock()) {
  144. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  145. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  146. return $this->getProductFamily()->getAvailableQuantity();
  147. break;
  148. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  149. return $this->getAvailableQuantity();
  150. break;
  151. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_UNLIMITED :
  152. return false;
  153. break;
  154. }
  155. }
  156. public function getTaxRateInherited()
  157. {
  158. return $this->getProductFamily()->getTaxRateInherited();
  159. }
  160. public function getProductFamily(): ?ProductFamilyInterface
  161. {
  162. return $this->productFamily;
  163. }
  164. public function setProductFamily(?ProductFamilyInterface $productFamily): self
  165. {
  166. $this->productFamily = $productFamily;
  167. return $this;
  168. }
  169. public function getTitle(): ?string
  170. {
  171. return $this->title;
  172. }
  173. public function setTitle(?string $title): self
  174. {
  175. $this->title = $title;
  176. return $this;
  177. }
  178. public function getOriginProduct(): ?bool
  179. {
  180. return $this->originProduct;
  181. }
  182. public function setOriginProduct(?bool $originProduct): self
  183. {
  184. $this->originProduct = $originProduct;
  185. return $this;
  186. }
  187. }