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.

162 lines
4.6KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Lc\ShopBundle\Context\PriceInterface;
  5. /**
  6. * @ORM\MappedSuperclass()
  7. */
  8. abstract class OrderProduct implements PriceInterface
  9. {
  10. use PriceTrait ;
  11. /**
  12. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\OrderShopInterface", inversedBy="orderProducts", cascade={"persist"})
  13. * @ORM\JoinColumn(nullable=false)
  14. */
  15. protected $orderShop;
  16. /**
  17. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\ProductInterface", inversedBy="orderProducts"))
  18. */
  19. protected $product;
  20. /**
  21. * @ORM\Column(type="integer")
  22. */
  23. protected $quantityOrder;
  24. /**
  25. * @ORM\Column(type="float")
  26. */
  27. protected $quantityProduct;
  28. /**
  29. * @ORM\Column(type="string", length=255)
  30. */
  31. protected $title;
  32. public function __toString()
  33. {
  34. if($this->getTitle()) {
  35. return $this->getTitle();
  36. }
  37. else{
  38. return $this->getProduct()->getProductFamily()->getTitle(). ' - '.$this->getProduct()->getTitle();
  39. }
  40. }
  41. public function getTitleOrderShop()
  42. {
  43. $product = $this->getProduct() ;
  44. $productFamily = $product->getProductFamily() ;
  45. $titleProduct = $product->getTitleInherited() ;
  46. $titleProductFamily = $productFamily->getTitle() ;
  47. if(strlen($titleProduct) > 0 && strlen($titleProductFamily) > 0) {
  48. $title = $titleProductFamily.' - '.$titleProduct ;
  49. }
  50. else {
  51. $title = strlen($titleProduct) ? $titleProduct : $titleProductFamily ;
  52. }
  53. if($productFamily->hasProductsWithVariousWeight()) {
  54. $title .= ' - '.$product->getQuantityLabelInherited() ;
  55. }
  56. return $title ;
  57. }
  58. public function getTitleSummaryAfterAddCart()
  59. {
  60. $title = '' ;
  61. $product = $this->getProduct() ;
  62. $productFamily = $product->getProductFamily() ;
  63. $titleProduct = $product->getTitleInherited() ;
  64. $titleProductFamily = $productFamily->getTitle() ;
  65. // multiple
  66. if($productFamily->getActiveProducts() && $productFamily->getBehaviorAddToCart() == 'multiple') {
  67. $title .= $titleProduct ;
  68. if($productFamily->hasProductsWithVariousWeight()) {
  69. $title .= ' - '.$product->getQuantityLabelInherited() ;
  70. }
  71. }
  72. // simple
  73. if($productFamily->getBehaviorAddToCart() == 'simple') {
  74. if($productFamily->getActiveProducts()) {
  75. $title .= $titleProduct ;
  76. if($productFamily->hasProductsWithVariousWeight()) {
  77. $title .= ' - '.$product->getQuantityLabelInherited() ;
  78. }
  79. }
  80. }
  81. return $title ;
  82. }
  83. public function getOrderShop(): ?OrderShop
  84. {
  85. return $this->orderShop;
  86. }
  87. public function setOrderShop(?OrderShop $orderShop): self
  88. {
  89. $this->orderShop = $orderShop;
  90. return $this;
  91. }
  92. public function getProduct(): ?Product
  93. {
  94. return $this->product;
  95. }
  96. public function setProduct(?Product $product): self
  97. {
  98. $this->product = $product;
  99. return $this;
  100. }
  101. public function getQuantityOrder(): ?int
  102. {
  103. return $this->quantityOrder;
  104. }
  105. public function setQuantityOrder(int $quantityOrder): self
  106. {
  107. $this->quantityOrder = $quantityOrder;
  108. return $this;
  109. }
  110. public function getQuantityProduct(): ?float
  111. {
  112. return $this->quantityProduct;
  113. }
  114. public function setQuantityProduct(float $quantityProduct): self
  115. {
  116. $this->quantityProduct = $quantityProduct;
  117. return $this;
  118. }
  119. public function getTitle(): ?string
  120. {
  121. return $this->title;
  122. }
  123. public function setTitle(string $title): self
  124. {
  125. $this->title = $title;
  126. return $this;
  127. }
  128. }