<?php
namespace App\Entity\Shop\Product;
use App\Entity\BaseEntity;
use App\Entity\Shop\Shop\Shop;
use App\Repository\Shop\Product\ProductAttributeValueRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
#[ORM\Entity(repositoryClass: ProductAttributeValueRepository::class)]
class ProductAttributeValue extends BaseEntity
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?string $id;
#[ORM\Column(type: Types::TEXT)]
private ?string $value = null;
// Like Medium
#[ORM\ManyToOne(inversedBy: 'productAttributeValues')]
#[ORM\JoinColumn(nullable: false)]
private ?ProductAttribute $attribute = null;
// its Size for Example
#[ORM\ManyToOne(inversedBy: 'productAttributeValues')]
#[ORM\JoinColumn(nullable: false)]
private ?Shop $shop = null;
#[ORM\ManyToMany(targetEntity: ProductPrice::class, mappedBy: 'selectedValues')]
private Collection $productPrices;
public function __construct()
{
parent::__construct();
$this->productPrices = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getValue(): ?string
{
return $this->value;
}
public function setValue(string $value): static
{
$this->value = $value;
return $this;
}
public function getAttribute(): ?ProductAttribute
{
return $this->attribute;
}
public function setAttribute(?ProductAttribute $attribute): static
{
$this->attribute = $attribute;
return $this;
}
public function getAdditionalPrice(): ?float
{
return $this->additionalPrice;
}
public function setAdditionalPrice( $additionalPrice): static
{
// اگر خواستید null را تبدیل به 0.0 کنید:
$this->additionalPrice = $additionalPrice ?? 0.0;
return $this;
}
public function getShop(): ?Shop
{
return $this->shop;
}
public function setShop(?Shop $shop): static
{
$this->shop = $shop;
return $this;
}
public function getInStock(): ?int
{
return $this->inStock;
}
public function setInStock(?int $inStock): static
{
$this->inStock = $inStock;
return $this;
}
/**
* @return Collection<int, ProductPrice>
*/
public function getProductPrices(): Collection
{
return $this->productPrices;
}
public function addProductPrice(ProductPrice $productPrice): static
{
if (!$this->productPrices->contains($productPrice)) {
$this->productPrices->add($productPrice);
$productPrice->addSelectedValue($this);
}
return $this;
}
public function removeProductPrice(ProductPrice $productPrice): static
{
if ($this->productPrices->removeElement($productPrice)) {
$productPrice->removeSelectedValue($this);
}
return $this;
}
}