Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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