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.

216 lines
5.7KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Model\Order;
  3. use Lc\CaracoleBundle\Doctrine\Extension\PriceTrait;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Lc\CaracoleBundle\Doctrine\Extension\PriceInterface;
  6. use Lc\CaracoleBundle\Model\Product\ProductInterface;
  7. /**
  8. * @ORM\MappedSuperclass()
  9. */
  10. abstract class OrderProductModel implements PriceInterface
  11. {
  12. use PriceTrait;
  13. /**
  14. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Order\OrderShopInterface", inversedBy="orderProducts", cascade={"persist"})
  15. * @ORM\JoinColumn(nullable=false)
  16. */
  17. protected $orderShop;
  18. /**
  19. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Product\ProductInterface"))
  20. */
  21. protected $product;
  22. /**
  23. * @ORM\Column(type="integer")
  24. */
  25. protected $quantityOrder;
  26. /**
  27. * @ORM\Column(type="float")
  28. */
  29. protected $quantityProduct;
  30. /**
  31. * @ORM\Column(type="string", length=255)
  32. */
  33. protected $title;
  34. /**
  35. * @ORM\OneToOne(targetEntity="Lc\CaracoleBundle\Model\Order\OrderProductReductionCatalogInterface", cascade={"persist", "remove"})
  36. */
  37. protected $orderProductReductionCatalog;
  38. /**
  39. * @ORM\OneToOne(targetEntity="Lc\CaracoleBundle\Model\Order\OrderProductRefundInterface", mappedBy="orderProduct", cascade={"persist", "remove"})
  40. */
  41. protected $orderProductRefund;
  42. public function __toString()
  43. {
  44. if ($this->getTitle()) {
  45. return $this->getTitle();
  46. } else {
  47. return $this->getProduct()->getProductFamily()->getTitle() . ' - ' . $this->getProduct()->getTitle();
  48. }
  49. }
  50. public function getTitleOrderShop()
  51. {
  52. $product = $this->getProduct();
  53. $productFamily = $product->getProductFamily();
  54. $titleProduct = $product->getTitle();
  55. $titleProductFamily = $productFamily->getTitle();
  56. if (strlen($titleProduct) > 0 && strlen($titleProductFamily) > 0) {
  57. $title = $titleProductFamily . ' - ' . $titleProduct;
  58. } else {
  59. $title = strlen($titleProduct) ? $titleProduct : $titleProductFamily;
  60. }
  61. if ($productFamily->hasProductsWithVariousWeight()) {
  62. $title .= ' - ' . $product->getQuantityLabelInherited();
  63. }
  64. return $title;
  65. }
  66. public function getTitleSummaryAfterAddCart()
  67. {
  68. $title = '';
  69. $product = $this->getProduct();
  70. $productFamily = $product->getProductFamily();
  71. $titleProduct = $product->getTitleInherited();
  72. $titleProductFamily = $productFamily->getTitle();
  73. // multiple
  74. if ($productFamily->getActiveProducts() && $productFamily->getBehaviorAddToCart() == 'multiple') {
  75. $title .= $titleProduct;
  76. if ($productFamily->hasProductsWithVariousWeight()) {
  77. $title .= ' - ' . $product->getQuantityLabelInherited();
  78. }
  79. }
  80. // simple
  81. if ($productFamily->getBehaviorAddToCart() == 'simple') {
  82. if ($productFamily->getActiveProducts()) {
  83. $title .= $titleProduct;
  84. if ($productFamily->hasProductsWithVariousWeight()) {
  85. $title .= ' - ' . $product->getQuantityLabelInherited();
  86. }
  87. }
  88. }
  89. return $title;
  90. }
  91. // isOrderProductAvailable
  92. public function isAvailable()
  93. {
  94. return $this->getProduct()->isAvailable($this->getQuantityOrder());
  95. }
  96. // isOrderProductAvailableAddCart
  97. public function isAvailableAddCart(OrderShopInterface $orderShop = null)
  98. {
  99. $product = $this->getProduct();
  100. return $this->isProductAvailable($product, $this->getQuantityOrder(), true, $orderShop);
  101. }
  102. public function getOrderShop(): ?OrderShopInterface
  103. {
  104. return $this->orderShop;
  105. }
  106. public function setOrderShop(?OrderShopInterface $orderShop): self
  107. {
  108. $this->orderShop = $orderShop;
  109. return $this;
  110. }
  111. public function getProduct(): ?ProductInterface
  112. {
  113. return $this->product;
  114. }
  115. public function setProduct(?ProductInterface $product): self
  116. {
  117. $this->product = $product;
  118. return $this;
  119. }
  120. public function getQuantityOrder(): ?int
  121. {
  122. return $this->quantityOrder;
  123. }
  124. public function setQuantityOrder(int $quantityOrder): self
  125. {
  126. $this->quantityOrder = $quantityOrder;
  127. return $this;
  128. }
  129. public function getQuantityProduct(): ?float
  130. {
  131. return $this->quantityProduct;
  132. }
  133. public function setQuantityProduct(float $quantityProduct): self
  134. {
  135. $this->quantityProduct = $quantityProduct;
  136. return $this;
  137. }
  138. public function getTitle(): ?string
  139. {
  140. return $this->title;
  141. }
  142. public function setTitle(string $title): self
  143. {
  144. $this->title = $title;
  145. return $this;
  146. }
  147. public function getOrderProductReductionCatalog(): ?OrderProductReductionCatalogInterface
  148. {
  149. return $this->orderProductReductionCatalog;
  150. }
  151. public function setOrderProductReductionCatalog(?OrderProductReductionCatalogInterface $orderProductReductionCatalog): self
  152. {
  153. $this->orderProductReductionCatalog = $orderProductReductionCatalog;
  154. return $this;
  155. }
  156. public function getOrderProductRefund(): ?OrderProductRefundInterface
  157. {
  158. return $this->orderProductRefund;
  159. }
  160. public function setOrderProductRefund(OrderProductRefundInterface $orderProductRefund): self
  161. {
  162. $this->orderProductRefund = $orderProductRefund;
  163. // set the owning side of the relation if necessary
  164. if ($orderProductRefund->getOrderProduct() !== $this) {
  165. $orderProductRefund->setOrderProduct($this);
  166. }
  167. return $this;
  168. }
  169. }