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.

145 lines
4.2KB

  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="float")
  22. */
  23. protected $quantity;
  24. /**
  25. * @ORM\Column(type="string", length=255)
  26. */
  27. protected $title;
  28. public function __toString()
  29. {
  30. if($this->getTitle()) {
  31. return $this->getTitle();
  32. }
  33. else{
  34. return $this->getProduct()->getProductFamily()->getTitle(). ' - '.$this->getProduct()->getTitle();
  35. }
  36. }
  37. public function getTitleOrderShop()
  38. {
  39. $product = $this->getProduct() ;
  40. $productFamily = $product->getProductFamily() ;
  41. $titleProduct = $product->getTitleInherited() ;
  42. $titleProductFamily = $productFamily->getTitle() ;
  43. if(strlen($titleProduct) > 0 && strlen($titleProductFamily) > 0) {
  44. $title = $titleProductFamily.' - '.$titleProduct ;
  45. }
  46. else {
  47. $title = strlen($titleProduct) ? $titleProduct : $titleProductFamily ;
  48. }
  49. if($productFamily->hasProductsWithVariousWeight()) {
  50. $title .= ' - '.$product->getQuantityLabelInherited() ;
  51. }
  52. return $title ;
  53. }
  54. public function getTitleSummaryAfterAddCart()
  55. {
  56. $title = '' ;
  57. $product = $this->getProduct() ;
  58. $productFamily = $product->getProductFamily() ;
  59. $titleProduct = $product->getTitleInherited() ;
  60. $titleProductFamily = $productFamily->getTitle() ;
  61. // multiple
  62. if($productFamily->getActiveProducts() && $productFamily->getBehaviorAddToCart() == 'multiple') {
  63. $title .= $titleProduct ;
  64. if($productFamily->hasProductsWithVariousWeight()) {
  65. $title .= ' - '.$product->getQuantityLabelInherited() ;
  66. }
  67. }
  68. // simple
  69. if($productFamily->getBehaviorAddToCart() == 'simple') {
  70. if($productFamily->getActiveProducts()) {
  71. $title .= $titleProduct ;
  72. if($productFamily->hasProductsWithVariousWeight()) {
  73. $title .= ' - '.$product->getQuantityLabelInherited() ;
  74. }
  75. }
  76. }
  77. return $title ;
  78. }
  79. public function getOrderShop(): ?OrderShop
  80. {
  81. return $this->orderShop;
  82. }
  83. public function setOrderShop(?OrderShop $orderShop): self
  84. {
  85. $this->orderShop = $orderShop;
  86. return $this;
  87. }
  88. public function getProduct(): ?Product
  89. {
  90. return $this->product;
  91. }
  92. public function setProduct(?Product $product): self
  93. {
  94. $this->product = $product;
  95. return $this;
  96. }
  97. public function getQuantity(): ?float
  98. {
  99. return $this->quantity;
  100. }
  101. public function setQuantity(float $quantity): self
  102. {
  103. $this->quantity = $quantity;
  104. return $this;
  105. }
  106. public function getTitle(): ?string
  107. {
  108. return $this->title;
  109. }
  110. public function setTitle(string $title): self
  111. {
  112. $this->title = $title;
  113. return $this;
  114. }
  115. }