src/Entity/Cart/CartItem.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Cart;
  3. use App\Entity\MiniAbstractBase;
  4. use App\Entity\OnlineShop\Product;
  5. use App\Entity\PointsCatalog\CatalogGift;
  6. use App\Entity\PointsCatalog\CatalogSize;
  7. use App\Repository\Cart\CartItemRepository;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Money\Money;
  10. /**
  11.  * @ORM\Table(name="cart_item")
  12.  * @ORM\Entity(repositoryClass=CartItemRepository::class)
  13.  */
  14. class CartItem
  15. {
  16.     /**
  17.      * @ORM\Column(name="id", type="integer")
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue(strategy="AUTO")
  20.      */
  21.     private int $id;
  22.     /**
  23.      * @ORM\Column(name="quantity", type="integer")
  24.      */
  25.     private int $quantity;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity="App\Entity\Cart\Cart", inversedBy="cartitems", cascade={"persist"})
  28.      */
  29.     protected Cart $cart;
  30.     /**
  31.      * @ORM\ManyToOne(targetEntity="App\Entity\OnlineShop\Product", cascade={"persist"})
  32.      */
  33.     protected ?Product $item null;
  34.     /**
  35.      * @ORM\ManyToOne(targetEntity="App\Entity\PointsCatalog\CatalogGift", cascade={"persist"})
  36.      */
  37.     protected ?CatalogGift $giftItem null;
  38.     /**
  39.      * @ORM\Column(name="comment", type="text", nullable=true)
  40.      */
  41.     protected ?string $comment null;
  42.     /**
  43.      * @ORM\Column(name="rate_discount", type="integer", nullable=true)
  44.      */
  45.     protected ?int $rateDiscount null;
  46.     /**
  47.      * @ORM\Column(name="cost_discount", type="integer", nullable=true)
  48.      */
  49.     protected ?int $costDiscount null;
  50.     /**
  51.      * @ORM\Column(name="promotion", type="text", nullable=true)
  52.      */
  53.     protected ?string $promotion null;
  54.     /**
  55.      * @ORM\OneToOne(targetEntity="App\Entity\Cart\CartItemSize", mappedBy="cartItem", cascade={"persist"}, orphanRemoval=true)
  56.      */
  57.     private ?CartItemSize $size null;
  58.     public function getId(): int
  59.     {
  60.         return $this->id;
  61.     }
  62.     public function setQuantity(int $quantity): self
  63.     {
  64.         $this->quantity $quantity;
  65.         return $this;
  66.     }
  67.     public function getQuantity(): int
  68.     {
  69.         return $this->quantity;
  70.     }
  71.     public function setCart(Cart $cart): self
  72.     {
  73.         $this->cart $cart;
  74.         return $this;
  75.     }
  76.     public function getCart(): Cart
  77.     {
  78.         return $this->cart;
  79.     }
  80.     public function setItem(?Product $item): self
  81.     {
  82.         $this->item $item;
  83.         return $this;
  84.     }
  85.     public function getItem(): ?Product
  86.     {
  87.         return $this->item;
  88.     }
  89.     public function getGiftItem(): ?CatalogGift
  90.     {
  91.         return $this->giftItem;
  92.     }
  93.     public function setGiftItem(?CatalogGift $giftItem): self
  94.     {
  95.         $this->giftItem $giftItem;
  96.         return $this;
  97.     }
  98.     public function getComment(): ?string
  99.     {
  100.         return $this->comment;
  101.     }
  102.     public function setComment(?string $comment): self
  103.     {
  104.         $this->comment $comment;
  105.         return $this;
  106.     }
  107.     public function getRateDiscount(): ?int
  108.     {
  109.         return $this->rateDiscount;
  110.     }
  111.     public function setRateDiscount(?int $rateDiscount): self
  112.     {
  113.         $this->rateDiscount $rateDiscount;
  114.         return $this;
  115.     }
  116.     public function getCostDiscount(): ?int
  117.     {
  118.         return $this->costDiscount;
  119.     }
  120.     public function setCostDiscount(?int $costDiscount): self
  121.     {
  122.         $this->costDiscount $costDiscount;
  123.         return $this;
  124.     }
  125.     public function getPromotion(): ?string
  126.     {
  127.         return $this->promotion;
  128.     }
  129.     public function setPromotion(?string $promotion): self
  130.     {
  131.         $this->promotion $promotion;
  132.         return $this;
  133.     }
  134.     public function size(): ?CatalogSize
  135.     {
  136.         return $this->getSize()?->getSize();
  137.     }
  138.     public function getSize(): ?CartItemSize
  139.     {
  140.         return $this->size;
  141.     }
  142.     public function setSize(CartItemSize $size): self
  143.     {
  144.         $this->size $size;
  145.         return $this;
  146.     }
  147.     public function totalGiftPoints(): int
  148.     {
  149.         if (!$this->getGiftItem()) {
  150.             return 0;
  151.         }
  152.         return $this->quantity $this->getGiftItem()->getPointsValue();
  153.     }
  154.     public function giftPrice(): ?Money
  155.     {
  156.         if (!$this->getGiftItem()) {
  157.             return null;
  158.         }
  159.         return $this->giftItem->getProviders()->first()->getPrice();
  160.     }
  161.     public function __toString(): string
  162.     {
  163.         return $this->id ? (string) $this->id MiniAbstractBase::DEFAULT_EMPTY_STRING;
  164.     }
  165. }