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.

252 satır
6.8KB

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