<?php
namespace App\Entity\Shop\Cart;
use App\Entity\BaseEntity;
use App\Entity\Shop\Product\Product;
use App\Entity\Shop\Shop\Shop;
use App\Repository\Shop\Cart\CartItemRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
#[ORM\Entity(repositoryClass: CartItemRepository::class)]
class CartItem extends BaseEntity
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?string $id;
#[ORM\ManyToOne(inversedBy: 'cartItems')]
#[ORM\JoinColumn(nullable: false)]
private ?Cart $cart = null;
#[ORM\ManyToOne(inversedBy: 'cartItems')]
#[ORM\JoinColumn(nullable: false)]
private ?Product $product = null;
#[ORM\Column(type: Types::BIGINT)]
private ?string $quantity = null;
#[ORM\Column(type: Types::BIGINT)]
private ?string $price = null;
#[ORM\OneToMany(mappedBy: 'cartItem', targetEntity: CartItemAttribute::class)]
private Collection $cartItemAttributes;
#[ORM\ManyToOne(inversedBy: 'cartItems')]
#[ORM\JoinColumn(nullable: false)]
private ?Shop $shop = null;
public function __construct()
{
parent::__construct();
$this->cartItemAttributes = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getCart(): ?Cart
{
return $this->cart;
}
public function setCart(?Cart $cart): static
{
$this->cart = $cart;
return $this;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): static
{
$this->product = $product;
return $this;
}
public function getQuantity(): ?string
{
return $this->quantity;
}
public function setQuantity(string $quantity): static
{
$this->quantity = $quantity;
return $this;
}
public function getPrice(): ?string
{
return $this->price;
}
public function setPrice(string $price): static
{
$this->price = $price;
return $this;
}
/**
* @return Collection<int, CartItemAttribute>
*/
public function getCartItemAttributes(): Collection
{
return $this->cartItemAttributes;
}
public function addCartItemAttribute(CartItemAttribute $cartItemAttribute): static
{
if (!$this->cartItemAttributes->contains($cartItemAttribute)) {
$this->cartItemAttributes->add($cartItemAttribute);
$cartItemAttribute->setCartItem($this);
}
return $this;
}
public function removeCartItemAttribute(CartItemAttribute $cartItemAttribute): static
{
if ($this->cartItemAttributes->removeElement($cartItemAttribute)) {
// set the owning side to null (unless already changed)
if ($cartItemAttribute->getCartItem() === $this) {
$cartItemAttribute->setCartItem(null);
}
}
return $this;
}
public function getShop(): ?Shop
{
return $this->shop;
}
public function setShop(?Shop $shop): static
{
$this->shop = $shop;
return $this;
}
}