src/Flexy/ShopBundle/Entity/Product/AttributValue.php line 18

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Product;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Repository\Product\AttributValueRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. #[ApiResource(
  10.     normalizationContext: ['groups' => ['read']],
  11.     denormalizationContext: ['groups' => ['write']],
  12.     
  13.     )]
  14. #[ORM\Entity(repositoryClassAttributValueRepository::class)]
  15. class AttributValue implements \Stringable
  16. {
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column(type'integer')]
  20.     #[Groups(['read''write'])]
  21.     private $id;
  22.     #[Groups(['read''write'])]
  23.     #[ORM\Column(type'text'nullabletrue)]
  24.     private ?string $description null;
  25.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  26.     private ?\DateTimeImmutable $createdAt null;
  27.     #[ORM\ManyToOne(targetEntityAttribut::class, inversedBy'attributValues')]
  28.     #[Groups(['read''write'])]
  29.     private ?\App\Flexy\ShopBundle\Entity\Product\Attribut $attribut null;
  30.     #[ORM\Column(type'string'length255,nullable:true)]
  31.     private ?string $value null;
  32.     #[ORM\ManyToOne(targetEntityProduct::class, inversedBy'attributValues'cascade: ['persist'])]
  33.     private ?\App\Flexy\ShopBundle\Entity\Product\Product $product null;
  34.     #[ORM\Column(type'float'nullabletrue)]
  35.     #[Groups(['read''write'])]
  36.     private ?float $price null;
  37.     #[ORM\Column(type'integer'nullabletrue)]
  38.     #[Groups(['read''write'])]
  39.     private ?int $quantity null;
  40.     #[ORM\ManyToMany(targetEntityProductVariant::class, mappedBy'attributeValues')]
  41.     private \Doctrine\Common\Collections\Collection|array $productVariants;
  42.     #[ORM\Column(length255nullabletrue)]
  43.     private ?string $code null;
  44.     public function __construct()
  45.     {
  46.         $this->productVariants = new ArrayCollection();
  47.     }
  48.     public function __toString(): string
  49.     {
  50.         return $this->attribut ." : "$this->value;
  51.     }
  52.     public function getId(): ?int
  53.     {
  54.         return $this->id;
  55.     }
  56.     public function getDescription(): ?string
  57.     {
  58.         return $this->description;
  59.     }
  60.     public function setDescription(?string $description): self
  61.     {
  62.         $this->description $description;
  63.         return $this;
  64.     }
  65.     public function getCreatedAt(): ?\DateTimeImmutable
  66.     {
  67.         return $this->createdAt;
  68.     }
  69.     public function setCreatedAt(?\DateTimeImmutable $createdAt): self
  70.     {
  71.         $this->createdAt $createdAt;
  72.         return $this;
  73.     }
  74.     public function getAttribut(): ?Attribut
  75.     {
  76.         return $this->attribut;
  77.     }
  78.     public function setAttribut(?Attribut $attribut): self
  79.     {
  80.         $this->attribut $attribut;
  81.         return $this;
  82.     }
  83.     public function getValue(): ?string
  84.     {
  85.         return $this->value;
  86.     }
  87.     public function setValue(string $value): self
  88.     {
  89.         $this->value $value;
  90.         return $this;
  91.     }
  92.     public function getProduct(): ?Product
  93.     {
  94.         return $this->product;
  95.     }
  96.     public function setProduct(?Product $product): self
  97.     {
  98.         $this->product $product;
  99.         return $this;
  100.     }
  101.     public function getPrice(): ?float
  102.     {
  103.         return $this->price;
  104.     }
  105.     public function setPrice(?float $price): self
  106.     {
  107.         $this->price $price;
  108.         return $this;
  109.     }
  110.     public function getQuantity(): ?int
  111.     {
  112.         return $this->quantity;
  113.     }
  114.     public function setQuantity(?int $quantity): self
  115.     {
  116.         $this->quantity $quantity;
  117.         return $this;
  118.     }
  119.     /**
  120.      * @return Collection|ProductVariant[]
  121.      */
  122.     public function getProductVariants(): Collection
  123.     {
  124.         return $this->productVariants;
  125.     }
  126.     public function addProductVariant(ProductVariant $productVariant): self
  127.     {
  128.         if (!$this->productVariants->contains($productVariant)) {
  129.             $this->productVariants[] = $productVariant;
  130.             $productVariant->addAttributeValue($this);
  131.         }
  132.         return $this;
  133.     }
  134.     public function removeProductVariant(ProductVariant $productVariant): self
  135.     {
  136.         if ($this->productVariants->removeElement($productVariant)) {
  137.             $productVariant->removeAttributeValue($this);
  138.         }
  139.         return $this;
  140.     }
  141.     #[Groups(['read''write'])]
  142.     public function getAttributName(){
  143.         return $this->getAttribut()->getName();
  144.     }
  145.     public function getCode(): ?string
  146.     {
  147.         return $this->code;
  148.     }
  149.     public function setCode(?string $code): static
  150.     {
  151.         $this->code $code;
  152.         return $this;
  153.     }
  154. }