<?php
namespace App\Entity\Shop\Product;
use App\Entity\BaseEntity;
use App\Entity\Shop\Shop\Shop;
use App\Repository\Shop\Product\ProductAttributeRepository;
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: ProductAttributeRepository::class)]
class ProductAttribute extends BaseEntity
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?string $id;
#[ORM\Column(length: 255)]
private ?string $name = null;
// Like Size
#[ORM\ManyToOne(inversedBy: 'productAttributes')]
#[ORM\JoinColumn(nullable: false)]
private ?Product $product = null;
#[ORM\OneToMany(mappedBy: 'attribute', targetEntity: ProductAttributeValue::class)]
private Collection $productAttributeValues;
#[ORM\ManyToOne(inversedBy: 'productAttributes')]
#[ORM\JoinColumn(nullable: false)]
private ?Shop $shop = null;
public function __construct()
{
parent::__construct();
$this->productAttributeValues = new ArrayCollection();
}
public function getId(): ?string
{
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;
}
/**
* @return Collection<int, ProductAttributeValue>
*/
public function getProductAttributeValues(): Collection
{
return $this->productAttributeValues;
}
public function addProductAttributeValue(ProductAttributeValue $productAttributeValue): static
{
if (!$this->productAttributeValues->contains($productAttributeValue)) {
$this->productAttributeValues->add($productAttributeValue);
$productAttributeValue->setAttribute($this);
}
return $this;
}
public function removeProductAttributeValue(ProductAttributeValue $productAttributeValue): static
{
$productAttributeValue->setActive(0);
return $this;
if ($this->productAttributeValues->removeElement($productAttributeValue)) {
// set the owning side to null (unless already changed)
if ($productAttributeValue->getAttribute() === $this) {
$productAttributeValue->setAttribute(null);
}
}
return $this;
}
public function getShop(): ?Shop
{
return $this->shop;
}
public function setShop(?Shop $shop): static
{
$this->shop = $shop;
return $this;
}
}