src/Entity/Shop/Product/ProductAttributeValue.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Shop\Product;
  3. use App\Entity\BaseEntity;
  4. use App\Entity\Shop\Shop\Shop;
  5. use App\Repository\Shop\Product\ProductAttributeValueRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\DBAL\Types\Types;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  11. #[ORM\Entity(repositoryClassProductAttributeValueRepository::class)]
  12. class ProductAttributeValue 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\Column(typeTypes::TEXT)]
  20.     private ?string $value null;
  21. //    Like Medium
  22.     #[ORM\ManyToOne(inversedBy'productAttributeValues')]
  23.     #[ORM\JoinColumn(nullablefalse)]
  24.     private ?ProductAttribute $attribute null;
  25. //    its Size for Example
  26.     #[ORM\ManyToOne(inversedBy'productAttributeValues')]
  27.     #[ORM\JoinColumn(nullablefalse)]
  28.     private ?Shop $shop null;
  29.     #[ORM\ManyToMany(targetEntityProductPrice::class, mappedBy'selectedValues')]
  30.     private Collection $productPrices;
  31.     public function __construct()
  32.     {
  33.         parent::__construct();
  34.         $this->productPrices = new ArrayCollection();
  35.     }
  36.     public function getId(): ?string
  37.     {
  38.         return $this->id;
  39.     }
  40.     public function getValue(): ?string
  41.     {
  42.         return $this->value;
  43.     }
  44.     public function setValue(string $value): static
  45.     {
  46.         $this->value $value;
  47.         return $this;
  48.     }
  49.     public function getAttribute(): ?ProductAttribute
  50.     {
  51.         return $this->attribute;
  52.     }
  53.     public function setAttribute(?ProductAttribute $attribute): static
  54.     {
  55.         $this->attribute $attribute;
  56.         return $this;
  57.     }
  58.     public function getAdditionalPrice(): ?float
  59.     {
  60.         return $this->additionalPrice;
  61.     }
  62.     public function setAdditionalPrice$additionalPrice): static
  63.     {
  64.         // اگر خواستید null را تبدیل به 0.0 کنید:
  65.         $this->additionalPrice $additionalPrice ?? 0.0;
  66.         return $this;
  67.     }
  68.     public function getShop(): ?Shop
  69.     {
  70.         return $this->shop;
  71.     }
  72.     public function setShop(?Shop $shop): static
  73.     {
  74.         $this->shop $shop;
  75.         return $this;
  76.     }
  77.     public function getInStock(): ?int
  78.     {
  79.         return $this->inStock;
  80.     }
  81.     public function setInStock(?int $inStock): static
  82.     {
  83.         $this->inStock $inStock;
  84.         return $this;
  85.     }
  86.     /**
  87.      * @return Collection<int, ProductPrice>
  88.      */
  89.     public function getProductPrices(): Collection
  90.     {
  91.         return $this->productPrices;
  92.     }
  93.     public function addProductPrice(ProductPrice $productPrice): static
  94.     {
  95.         if (!$this->productPrices->contains($productPrice)) {
  96.             $this->productPrices->add($productPrice);
  97.             $productPrice->addSelectedValue($this);
  98.         }
  99.         return $this;
  100.     }
  101.     public function removeProductPrice(ProductPrice $productPrice): static
  102.     {
  103.         if ($this->productPrices->removeElement($productPrice)) {
  104.             $productPrice->removeSelectedValue($this);
  105.         }
  106.         return $this;
  107.     }
  108. }