src/Entity/Shop/Cart/Cart.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Shop\Cart;
  3. use App\Entity\BaseEntity;
  4. use App\Entity\Generic\Customer\Customer;
  5. use App\Entity\Shop\Shop\Shop;
  6. use App\Repository\Shop\CartRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  11. #[ORM\Entity(repositoryClassCartRepository::class)]
  12. class Cart extends BaseEntity
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\Column(type'guid'uniquetrue)]
  16.     #[ORM\GeneratedValue(strategy'CUSTOM')]
  17.     #[ORM\CustomIdGenerator(class: UuidGenerator::class)]
  18.     private ?string $id;
  19.     #[ORM\ManyToOne(inversedBy'carts')]
  20.     #[ORM\JoinColumn(nullablefalse)]
  21.     private ?Customer $customer null;
  22.     #[ORM\OneToMany(mappedBy'cart'targetEntityCartItem::class)]
  23.     private Collection $cartItems;
  24.     #[ORM\ManyToOne(inversedBy'carts')]
  25.     #[ORM\JoinColumn(nullablefalse)]
  26.     private ?Shop $shop null;
  27.     public function __construct()
  28.     {
  29.         parent::__construct();
  30.         $this->cartItems = new ArrayCollection();
  31.     }
  32.     public function getId(): ?string
  33.     {
  34.         return $this->id;
  35.     }
  36.     public function getCustomer(): ?Customer
  37.     {
  38.         return $this->customer;
  39.     }
  40.     public function setCustomer(?Customer $customer): static
  41.     {
  42.         $this->customer $customer;
  43.         return $this;
  44.     }
  45.     /**
  46.      * @return Collection<int, CartItem>
  47.      */
  48.     public function getCartItems(): Collection
  49.     {
  50.         return $this->cartItems;
  51.     }
  52.     public function addCartItem(CartItem $cartItem): static
  53.     {
  54.         if (!$this->cartItems->contains($cartItem)) {
  55.             $this->cartItems->add($cartItem);
  56.             $cartItem->setCart($this);
  57.         }
  58.         return $this;
  59.     }
  60.     public function removeCartItem(CartItem $cartItem): static
  61.     {
  62.         if ($this->cartItems->removeElement($cartItem)) {
  63.             // set the owning side to null (unless already changed)
  64.             if ($cartItem->getCart() === $this) {
  65.                 $cartItem->setCart(null);
  66.             }
  67.         }
  68.         return $this;
  69.     }
  70.     public function getShop(): ?Shop
  71.     {
  72.         return $this->shop;
  73.     }
  74.     public function setShop(?Shop $shop): static
  75.     {
  76.         $this->shop $shop;
  77.         return $this;
  78.     }
  79. }