182 line
5.3KB

  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. public function __toString()
  38. {
  39. if($this->getTitle()) {
  40. return $this->getTitle();
  41. }
  42. else{
  43. return $this->getProduct()->getProductFamily()->getTitle(). ' - '.$this->getProduct()->getTitle();
  44. }
  45. }
  46. public function getTitleOrderShop()
  47. {
  48. $product = $this->getProduct() ;
  49. $productFamily = $product->getProductFamily() ;
  50. $titleProduct = $product->getTitle() ;
  51. $titleProductFamily = $productFamily->getTitle() ;
  52. if(strlen($titleProduct) > 0 && strlen($titleProductFamily) > 0) {
  53. $title = $titleProductFamily.' - '.$titleProduct ;
  54. }
  55. else {
  56. $title = strlen($titleProduct) ? $titleProduct : $titleProductFamily ;
  57. }
  58. if($productFamily->hasProductsWithVariousWeight()) {
  59. $title .= ' - '.$product->getQuantityLabelInherited() ;
  60. }
  61. return $title ;
  62. }
  63. public function getTitleSummaryAfterAddCart()
  64. {
  65. $title = '' ;
  66. $product = $this->getProduct() ;
  67. $productFamily = $product->getProductFamily() ;
  68. $titleProduct = $product->getTitleInherited() ;
  69. $titleProductFamily = $productFamily->getTitle() ;
  70. // multiple
  71. if($productFamily->getActiveProducts() && $productFamily->getBehaviorAddToCart() == 'multiple') {
  72. $title .= $titleProduct ;
  73. if($productFamily->hasProductsWithVariousWeight()) {
  74. $title .= ' - '.$product->getQuantityLabelInherited() ;
  75. }
  76. }
  77. // simple
  78. if($productFamily->getBehaviorAddToCart() == 'simple') {
  79. if($productFamily->getActiveProducts()) {
  80. $title .= $titleProduct ;
  81. if($productFamily->hasProductsWithVariousWeight()) {
  82. $title .= ' - '.$product->getQuantityLabelInherited() ;
  83. }
  84. }
  85. }
  86. return $title ;
  87. }
  88. public function getOrderShop(): ?OrderShop
  89. {
  90. return $this->orderShop;
  91. }
  92. public function setOrderShop(?OrderShop $orderShop): self
  93. {
  94. $this->orderShop = $orderShop;
  95. return $this;
  96. }
  97. public function getProduct(): ?Product
  98. {
  99. return $this->product;
  100. }
  101. public function setProduct(?Product $product): self
  102. {
  103. $this->product = $product;
  104. return $this;
  105. }
  106. public function getQuantityOrder(): ?int
  107. {
  108. return $this->quantityOrder;
  109. }
  110. public function setQuantityOrder(int $quantityOrder): self
  111. {
  112. $this->quantityOrder = $quantityOrder;
  113. return $this;
  114. }
  115. public function getQuantityProduct(): ?float
  116. {
  117. return $this->quantityProduct;
  118. }
  119. public function setQuantityProduct(float $quantityProduct): self
  120. {
  121. $this->quantityProduct = $quantityProduct;
  122. return $this;
  123. }
  124. public function getTitle(): ?string
  125. {
  126. return $this->title;
  127. }
  128. public function setTitle(string $title): self
  129. {
  130. $this->title = $title;
  131. return $this;
  132. }
  133. public function getOrderProductReductionCatalog(): ?OrderProductReductionCatalog
  134. {
  135. return $this->orderProductReductionCatalog;
  136. }
  137. public function setOrderProductReductionCatalog(?OrderProductReductionCatalog $orderProductReductionCatalog): self
  138. {
  139. $this->orderProductReductionCatalog = $orderProductReductionCatalog;
  140. return $this;
  141. }
  142. }