|
- <?php
-
- namespace Lc\ShopBundle\Model;
-
- use Doctrine\ORM\Mapping as ORM;
- use Lc\ShopBundle\Context\PriceInterface;
-
- /**
- * @ORM\MappedSuperclass()
- */
- abstract class OrderProduct implements PriceInterface
- {
- use PriceTrait ;
-
- /**
- * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\OrderShopInterface", inversedBy="orderProducts", cascade={"persist"})
- * @ORM\JoinColumn(nullable=false)
- */
- protected $orderShop;
-
- /**
- * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\ProductInterface", inversedBy="orderProducts"))
- */
- protected $product;
-
- /**
- * @ORM\Column(type="float")
- */
- protected $quantity;
-
- /**
- * @ORM\Column(type="string", length=255)
- */
- protected $title;
-
- public function __toString()
- {
- if($this->getTitle()) {
- return $this->getTitle();
- }
- else{
- return $this->getProduct()->getProductFamily()->getTitle(). ' - '.$this->getProduct()->getTitle();
- }
- }
-
- public function getTitleOrderShop()
- {
- $product = $this->getProduct() ;
- $productFamily = $product->getProductFamily() ;
- $titleProduct = $product->getTitleInherited() ;
- $titleProductFamily = $productFamily->getTitle() ;
-
- if(strlen($titleProduct) > 0 && strlen($titleProductFamily) > 0) {
- $title = $titleProductFamily.' - '.$titleProduct ;
- }
- else {
- $title = strlen($titleProduct) ? $titleProduct : $titleProductFamily ;
- }
-
- if($productFamily->hasProductsWithVariousWeight()) {
- $title .= ' - '.$product->getQuantityLabelInherited() ;
- }
-
- return $title ;
- }
-
- public function getTitleSummaryAfterAddCart()
- {
- $title = '' ;
-
- $product = $this->getProduct() ;
- $productFamily = $product->getProductFamily() ;
- $titleProduct = $product->getTitleInherited() ;
- $titleProductFamily = $productFamily->getTitle() ;
-
- // multiple
- if($productFamily->getActiveProducts() && $productFamily->getBehaviorAddToCart() == 'multiple') {
- $title .= $titleProduct ;
- if($productFamily->hasProductsWithVariousWeight()) {
- $title .= ' - '.$product->getQuantityLabelInherited() ;
- }
- }
-
- // simple
- if($productFamily->getBehaviorAddToCart() == 'simple') {
- if($productFamily->getActiveProducts()) {
- $title .= $titleProduct ;
- if($productFamily->hasProductsWithVariousWeight()) {
- $title .= ' - '.$product->getQuantityLabelInherited() ;
- }
- }
- }
-
- return $title ;
- }
-
- public function getOrderShop(): ?OrderShop
- {
- return $this->orderShop;
- }
-
- public function setOrderShop(?OrderShop $orderShop): self
- {
- $this->orderShop = $orderShop;
-
- return $this;
- }
-
- public function getProduct(): ?Product
- {
- return $this->product;
- }
-
- public function setProduct(?Product $product): self
- {
- $this->product = $product;
-
- return $this;
- }
-
- public function getQuantity(): ?float
- {
- return $this->quantity;
- }
-
- public function setQuantity(float $quantity): self
- {
- $this->quantity = $quantity;
-
- return $this;
- }
-
- public function getTitle(): ?string
- {
- return $this->title;
- }
-
- public function setTitle(string $title): self
- {
- $this->title = $title;
-
- return $this;
- }
- }
|