src/Entity/ProduitVariant.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProduitVariantRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassProduitVariantRepository::class)]
  9. class ProduitVariant
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length255nullabletrue)]
  16.     private ?string $size null;
  17.     #[ORM\Column(length255nullabletrue)]
  18.     private ?string $color null;
  19.     // ── Values for up to 3 dimensions (e.g. "Lavender", "50ml", "Red") ──
  20.     #[ORM\Column(length255nullabletrue)]
  21.     private ?string $optionLabel null;
  22.     #[ORM\Column(length255nullabletrue)]
  23.     private ?string $optionLabel2 null;
  24.     #[ORM\Column(length255nullabletrue)]
  25.     private ?string $optionLabel3 null;
  26.     #[ORM\Column(typeTypes::DECIMALprecision10scale2)]
  27.     private ?string $prix null;
  28.     // ── per-variant cost (for profit reports); nullable, falls back to product cost ──
  29.     #[ORM\Column(typeTypes::DECIMALprecision10scale2nullabletrue)]
  30.     private ?string $cost_price null;
  31.     #[ORM\ManyToOne(inversedBy'produitVariants')]
  32.     #[ORM\JoinColumn(nullablefalse)]
  33.     private ?Produit $produit null;
  34.     #[ORM\Column(typeTypes::DECIMALprecision10scale2)]
  35.     private ?string $qtt null;
  36.     #[ORM\OneToMany(mappedBy'produitVariant'targetEntityCommandeDetails::class)]
  37.     private Collection $commandeDetails;
  38.     #[ORM\ManyToOne(inversedBy'produitVariants')]
  39.     private ?ParamColor $paramColor null;
  40.     #[ORM\ManyToOne(inversedBy'produitVariants')]
  41.     private ?ParamSize $paramSize null;
  42.     // ── images that belong to this variant ──
  43.     #[ORM\OneToMany(mappedBy'produitVariant'targetEntityImage::class)]
  44.     private Collection $images;
  45.     public function __construct()
  46.     {
  47.         $this->commandeDetails = new ArrayCollection();
  48.         $this->images = new ArrayCollection();
  49.     }
  50.     public function getId(): ?int
  51.     {
  52.         return $this->id;
  53.     }
  54.     public function getOptionLabel(): ?string
  55.     {
  56.         return $this->optionLabel;
  57.     }
  58.     public function setOptionLabel(?string $optionLabel): static
  59.     {
  60.         $this->optionLabel $optionLabel;
  61.         return $this;
  62.     }
  63.     public function getOptionLabel2(): ?string
  64.     {
  65.         return $this->optionLabel2;
  66.     }
  67.     public function setOptionLabel2(?string $optionLabel2): static
  68.     {
  69.         $this->optionLabel2 $optionLabel2;
  70.         return $this;
  71.     }
  72.     public function getOptionLabel3(): ?string
  73.     {
  74.         return $this->optionLabel3;
  75.     }
  76.     public function setOptionLabel3(?string $optionLabel3): static
  77.     {
  78.         $this->optionLabel3 $optionLabel3;
  79.         return $this;
  80.     }
  81.     public function getPrix(): ?string
  82.     {
  83.         return $this->prix;
  84.     }
  85.     public function setPrix(?string $prix): static
  86.     {
  87.         $this->prix $prix;
  88.         return $this;
  89.     }
  90.     public function getCostPrice(): ?string
  91.     {
  92.         return $this->cost_price;
  93.     }
  94.     public function setCostPrice(?string $cost_price): static
  95.     {
  96.         $this->cost_price $cost_price;
  97.         return $this;
  98.     }
  99.     public function getProduit(): ?Produit
  100.     {
  101.         return $this->produit;
  102.     }
  103.     public function setProduit(?Produit $produit): static
  104.     {
  105.         $this->produit $produit;
  106.         return $this;
  107.     }
  108.     public function getQtt(): ?string
  109.     {
  110.         return $this->qtt;
  111.     }
  112.     public function setQtt(?string $qtt): static
  113.     {
  114.         $this->qtt $qtt;
  115.         return $this;
  116.     }
  117.     public function __toString(): string{
  118.         $parts array_filter([$this->optionLabel$this->optionLabel2$this->optionLabel3]);
  119.         if (!empty($parts)) {
  120.             return implode(' · '$parts);
  121.         }
  122.         return (string) ($this->color ?? '');
  123.     }
  124.     /**
  125.      * @return Collection<int, CommandeDetails>
  126.      */
  127.     public function getCommandeDetails(): Collection
  128.     {
  129.         return $this->commandeDetails;
  130.     }
  131.     public function addCommandeDetail(CommandeDetails $commandeDetail): static
  132.     {
  133.         if (!$this->commandeDetails->contains($commandeDetail)) {
  134.             $this->commandeDetails->add($commandeDetail);
  135.             $commandeDetail->setProduitVariant($this);
  136.         }
  137.         return $this;
  138.     }
  139.     public function removeCommandeDetail(CommandeDetails $commandeDetail): static
  140.     {
  141.         if ($this->commandeDetails->removeElement($commandeDetail)) {
  142.             if ($commandeDetail->getProduitVariant() === $this) {
  143.                 $commandeDetail->setProduitVariant(null);
  144.             }
  145.         }
  146.         return $this;
  147.     }
  148.     public function getParamColor(): ?ParamColor
  149.     {
  150.         return $this->paramColor;
  151.     }
  152.     public function setParamColor(?ParamColor $paramColor): static
  153.     {
  154.         $this->paramColor $paramColor;
  155.         return $this;
  156.     }
  157.     public function getParamSize(): ?ParamSize
  158.     {
  159.         return $this->paramSize;
  160.     }
  161.     public function setParamSize(?ParamSize $paramSize): static
  162.     {
  163.         $this->paramSize $paramSize;
  164.         return $this;
  165.     }
  166.     /**
  167.      * @return Collection<int, Image>
  168.      */
  169.     public function getImages(): Collection
  170.     {
  171.         return $this->images;
  172.     }
  173.     public function addImage(Image $image): static
  174.     {
  175.         if (!$this->images->contains($image)) {
  176.             $this->images->add($image);
  177.             $image->setProduitVariant($this);
  178.         }
  179.         return $this;
  180.     }
  181.     public function removeImage(Image $image): static
  182.     {
  183.         if ($this->images->removeElement($image)) {
  184.             if ($image->getProduitVariant() === $this) {
  185.                 $image->setProduitVariant(null);
  186.             }
  187.         }
  188.         return $this;
  189.     }
  190. }