<?php
namespace App\Entity;
use App\Repository\ShoppingCartDetailRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Blameable\Traits\BlameableEntity;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: ShoppingCartDetailRepository::class)]
class ShoppingCartDetail
{
use BlameableEntity; //Hook blameable behaviour. Updates createdBy, updatedBy fields
use TimestampableEntity; //Hook timestampable behaviour. Updates createdAt, updatedAt fields
#[ORM\Id]
#[ORM\GeneratedValue(strategy: "IDENTITY")]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'shoppingCartDetails')]
#[ORM\JoinColumn(nullable: false)]
#[Assert\NotNull()]
private ?ShoppingCart $header = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
#[Assert\NotNull()]
private ?Product $product = null;
#[ORM\Column]
#[Assert\NotNull()]
#[Assert\Positive()]
#[Assert\Expression(
"!this.getProduct().getLimitUnitsPerBuyer() or value <= this.getProduct().getLimitUnitsPerBuyer()",
)]
private ?int $quantity = null;
public function __toString()
{
return ($this->header ? $this->header->getId() : "") . "_" . $this->id;
}
public function getId(): ?int
{
return $this->id;
}
public function getHeader(): ?ShoppingCart
{
return $this->header;
}
public function setHeader(?ShoppingCart $header): self
{
$this->header = $header;
return $this;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): self
{
$this->product = $product;
return $this;
}
public function getQuantity(): ?int
{
return $this->quantity;
}
public function setQuantity(int $quantity): self
{
$this->quantity = $quantity;
return $this;
}
}