<?php
namespace App\Entity\Product;
use App\Entity\Order\SaleItem;
use App\Repository\Product\ProductVariantRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ProductVariantRepository::class)]
class ProductVariant
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 150)]
private ?string $name = null;
#[ORM\ManyToOne(inversedBy: 'productVariants', cascade: ['persist'])]
private ?Product $product = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]
private ?string $price = null;
#[ORM\Column(nullable: true)]
private ?int $stock_quantity = null;
#[ORM\Column(length: 50, nullable: true)]
private ?string $reference = null;
#[ORM\Column(length: 60, nullable: true)]
private ?string $slug = null;
#[ORM\OneToMany(mappedBy: 'productVariant', targetEntity: ProductAttributeValue::class, cascade: ['persist', 'remove'])]
private Collection $productAttributesValues;
#[ORM\OneToMany(mappedBy: 'productVariant', targetEntity: ProductImage::class)]
private Collection $productImages;
#[ORM\OneToOne(mappedBy: 'productVariant', cascade: ['persist', 'remove'])]
private ?SaleItem $saleItem = null;
#[ORM\Column(length: 50, nullable: true)]
private ?string $promotion = null;
public function __construct()
{
$this->productAttributesValues = new ArrayCollection();
$this->productImages = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): static
{
$this->product = $product;
return $this;
}
public function getPrice(): ?string
{
return $this->price;
}
public function setPrice(?string $price): static
{
$this->price = $price;
return $this;
}
public function getStockQuantity(): ?int
{
return $this->stock_quantity;
}
public function setStockQuantity(?int $stock_quantity): static
{
$this->stock_quantity = $stock_quantity;
return $this;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(?string $reference): static
{
$this->reference = $reference;
return $this;
}
/**
* @return Collection<int, ProductAttributeValue>
*/
public function getProductAttributesValues(): Collection
{
return $this->productAttributesValues;
}
public function addProductAttributesValue(ProductAttributeValue $productAttributesValue): static
{
if (!$this->productAttributesValues->contains($productAttributesValue)) {
$this->productAttributesValues->add($productAttributesValue);
$productAttributesValue->setProductVariant($this);
}
return $this;
}
public function removeProductAttributesValue(ProductAttributeValue $productAttributesValue): static
{
if ($this->productAttributesValues->removeElement($productAttributesValue)) {
// set the owning side to null (unless already changed)
if ($productAttributesValue->getProductVariant() === $this) {
$productAttributesValue->setProductVariant(null);
}
}
return $this;
}
/**
* @return Collection<int, ProductImage>
*/
public function getProductImages(): Collection
{
return $this->productImages;
}
public function addProductImage(ProductImage $productImage): static
{
if (!$this->productImages->contains($productImage)) {
$this->productImages->add($productImage);
$productImage->setProductVariant($this);
}
return $this;
}
public function removeProductImage(ProductImage $productImage): static
{
if ($this->productImages->removeElement($productImage)) {
// set the owning side to null (unless already changed)
if ($productImage->getProductVariant() === $this) {
$productImage->setProductVariant(null);
}
}
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): static
{
$this->slug = $slug;
return $this;
}
public function getSaleItem(): ?SaleItem
{
return $this->saleItem;
}
public function setSaleItem(?SaleItem $saleItem): static
{
// unset the owning side of the relation if necessary
if ($saleItem === null && $this->saleItem !== null) {
$this->saleItem->setProductVariant(null);
}
// set the owning side of the relation if necessary
if ($saleItem !== null && $saleItem->getProductVariant() !== $this) {
$saleItem->setProductVariant($this);
}
$this->saleItem = $saleItem;
return $this;
}
public function getPromotion(): ?string
{
return $this->promotion;
}
public function setPromotion(?string $promotion): static
{
$this->promotion = $promotion;
return $this;
}
}