選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

OrderProduct.php 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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"))
  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. }