Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

203 linhas
5.3KB

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