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.

203 lines
6.0KB

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