<?php
namespace App\Entity\Shop\Cart;
use App\Entity\BaseEntity;
use App\Entity\Generic\Customer\Customer;
use App\Entity\Shop\Shop\Shop;
use App\Repository\Shop\CartRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
#[ORM\Entity(repositoryClass: CartRepository::class)]
class Cart 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: 'carts')]
#[ORM\JoinColumn(nullable: false)]
private ?Customer $customer = null;
#[ORM\OneToMany(mappedBy: 'cart', targetEntity: CartItem::class)]
private Collection $cartItems;
#[ORM\ManyToOne(inversedBy: 'carts')]
#[ORM\JoinColumn(nullable: false)]
private ?Shop $shop = null;
public function __construct()
{
parent::__construct();
$this->cartItems = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getCustomer(): ?Customer
{
return $this->customer;
}
public function setCustomer(?Customer $customer): static
{
$this->customer = $customer;
return $this;
}
/**
* @return Collection<int, CartItem>
*/
public function getCartItems(): Collection
{
return $this->cartItems;
}
public function addCartItem(CartItem $cartItem): static
{
if (!$this->cartItems->contains($cartItem)) {
$this->cartItems->add($cartItem);
$cartItem->setCart($this);
}
return $this;
}
public function removeCartItem(CartItem $cartItem): static
{
if ($this->cartItems->removeElement($cartItem)) {
// set the owning side to null (unless already changed)
if ($cartItem->getCart() === $this) {
$cartItem->setCart(null);
}
}
return $this;
}
public function getShop(): ?Shop
{
return $this->shop;
}
public function setShop(?Shop $shop): static
{
$this->shop = $shop;
return $this;
}
}