src/Flexy/ShopBundle/Entity/Product/ProductVariant.php line 13

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Product;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Repository\Product\ProductVariantRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ApiResource]
  9. #[ORM\Entity(repositoryClassProductVariantRepository::class)]
  10. class ProductVariant
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column(type'integer')]
  15.     private $id;
  16.     #[ORM\Column(type'string'length255)]
  17.     private ?string $name null;
  18.     #[ORM\ManyToMany(targetEntityAttributValue::class, inversedBy'productVariants')]
  19.     private \Doctrine\Common\Collections\Collection|array $attributeValues;
  20.     #[ORM\ManyToOne(targetEntityProduct::class, inversedBy'productVariants'cascade: ['persist'])]
  21.     private ?\App\Flexy\ShopBundle\Entity\Product\Product $product null;
  22.     #[ORM\Column(type'integer'nullabletrue)]
  23.     private ?int $quantity null;
  24.     #[ORM\Column(type'float')]
  25.     private ?float $price null;
  26.     public function __construct()
  27.     {
  28.         $this->attributeValues = new ArrayCollection();
  29.     }
  30.     public function getId(): ?int
  31.     {
  32.         return $this->id;
  33.     }
  34.     public function getName(): ?string
  35.     {
  36.         return $this->name;
  37.     }
  38.     public function setName(string $name): self
  39.     {
  40.         $this->name $name;
  41.         return $this;
  42.     }
  43.     /**
  44.      * @return Collection|AttributValue[]
  45.      */
  46.     public function getAttributeValues(): Collection
  47.     {
  48.         return $this->attributeValues;
  49.     }
  50.     public function addAttributeValue(AttributValue $attributeValue): self
  51.     {
  52.         if (!$this->attributeValues->contains($attributeValue)) {
  53.             $this->attributeValues[] = $attributeValue;
  54.         }
  55.         return $this;
  56.     }
  57.     public function removeAttributeValue(AttributValue $attributeValue): self
  58.     {
  59.         $this->attributeValues->removeElement($attributeValue);
  60.         return $this;
  61.     }
  62.     public function getProduct(): ?Product
  63.     {
  64.         return $this->product;
  65.     }
  66.     public function setProduct(?Product $product): self
  67.     {
  68.         $this->product $product;
  69.         return $this;
  70.     }
  71.     public function getQuantity(): ?int
  72.     {
  73.         return $this->quantity;
  74.     }
  75.     public function setQuantity(?int $quantity): self
  76.     {
  77.         $this->quantity $quantity;
  78.         return $this;
  79.     }
  80.     public function getPrice(): ?float
  81.     {
  82.         return $this->price;
  83.     }
  84.     public function setPrice(float $price): self
  85.     {
  86.         $this->price $price;
  87.         return $this;
  88.     }
  89. }