<?php
namespace App\Entity\Cart;
use App\Entity\MiniAbstractBase;
use App\Entity\OnlineShop\Product;
use App\Entity\PointsCatalog\CatalogGift;
use App\Entity\PointsCatalog\CatalogSize;
use App\Repository\Cart\CartItemRepository;
use Doctrine\ORM\Mapping as ORM;
use Money\Money;
/**
* @ORM\Table(name="cart_item")
* @ORM\Entity(repositoryClass=CartItemRepository::class)
*/
class CartItem
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private int $id;
/**
* @ORM\Column(name="quantity", type="integer")
*/
private int $quantity;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Cart\Cart", inversedBy="cartitems", cascade={"persist"})
*/
protected Cart $cart;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\OnlineShop\Product", cascade={"persist"})
*/
protected ?Product $item = null;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\PointsCatalog\CatalogGift", cascade={"persist"})
*/
protected ?CatalogGift $giftItem = null;
/**
* @ORM\Column(name="comment", type="text", nullable=true)
*/
protected ?string $comment = null;
/**
* @ORM\Column(name="rate_discount", type="integer", nullable=true)
*/
protected ?int $rateDiscount = null;
/**
* @ORM\Column(name="cost_discount", type="integer", nullable=true)
*/
protected ?int $costDiscount = null;
/**
* @ORM\Column(name="promotion", type="text", nullable=true)
*/
protected ?string $promotion = null;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Cart\CartItemSize", mappedBy="cartItem", cascade={"persist"}, orphanRemoval=true)
*/
private ?CartItemSize $size = null;
public function getId(): int
{
return $this->id;
}
public function setQuantity(int $quantity): self
{
$this->quantity = $quantity;
return $this;
}
public function getQuantity(): int
{
return $this->quantity;
}
public function setCart(Cart $cart): self
{
$this->cart = $cart;
return $this;
}
public function getCart(): Cart
{
return $this->cart;
}
public function setItem(?Product $item): self
{
$this->item = $item;
return $this;
}
public function getItem(): ?Product
{
return $this->item;
}
public function getGiftItem(): ?CatalogGift
{
return $this->giftItem;
}
public function setGiftItem(?CatalogGift $giftItem): self
{
$this->giftItem = $giftItem;
return $this;
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): self
{
$this->comment = $comment;
return $this;
}
public function getRateDiscount(): ?int
{
return $this->rateDiscount;
}
public function setRateDiscount(?int $rateDiscount): self
{
$this->rateDiscount = $rateDiscount;
return $this;
}
public function getCostDiscount(): ?int
{
return $this->costDiscount;
}
public function setCostDiscount(?int $costDiscount): self
{
$this->costDiscount = $costDiscount;
return $this;
}
public function getPromotion(): ?string
{
return $this->promotion;
}
public function setPromotion(?string $promotion): self
{
$this->promotion = $promotion;
return $this;
}
public function size(): ?CatalogSize
{
return $this->getSize()?->getSize();
}
public function getSize(): ?CartItemSize
{
return $this->size;
}
public function setSize(CartItemSize $size): self
{
$this->size = $size;
return $this;
}
public function totalGiftPoints(): int
{
if (!$this->getGiftItem()) {
return 0;
}
return $this->quantity * $this->getGiftItem()->getPointsValue();
}
public function giftPrice(): ?Money
{
if (!$this->getGiftItem()) {
return null;
}
return $this->giftItem->getProviders()->first()->getPrice();
}
public function __toString(): string
{
return $this->id ? (string) $this->id : MiniAbstractBase::DEFAULT_EMPTY_STRING;
}
}