src/Entity/TrProduits.php line 46

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\TrProduitsRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use ApiPlatform\Core\Annotation\ApiResource;
  8. use ApiPlatform\Core\Annotation\ApiProperty;
  9. use ApiPlatform\Core\Annotation\ApiFilter;
  10. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  11. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  12. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. use Symfony\Component\Serializer\Annotation\SerializedName;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  17. /**
  18.  * @ORM\Entity(repositoryClass=TrProduitsRepository::class)
  19.  * @ApiResource(
  20.  *   routePrefix="/v1",
  21.  *   normalizationContext={"groups"={"produit:read"}},
  22.  *   denormalizationContext={"groups"={"produit:write"}},
  23.  *   paginationEnabled=false,
  24.  *   collectionOperations={
  25.  *     "get"={"path"="/tr_produits"},
  26.  *     "post"={"path"="/tr_produits"}
  27.  *   },
  28.  *   itemOperations={
  29.  *     "get"={"path"="/tr_produits/{id}"},
  30.  *     "put"={"path"="/tr_produits/{id}"},
  31.  *     "patch"={"path"="/tr_produits/{id}"},
  32.  *     "delete"={"path"="/tr_produits/{id}"}
  33.  *   }
  34.  * )
  35.  * @ApiFilter(SearchFilter::class, properties={
  36.  *   "LIBELLE": "partial",
  37.  *   "Description": "partial",
  38.  *   "CATEGORIES": "partial",
  39.  *   "ALIAS": "partial"
  40.  * })
  41.  * @ApiFilter(OrderFilter::class, properties={"PRIX","id"})
  42.  */
  43. class TrProduits
  44. {
  45.     /**
  46.      * @ORM\Id
  47.      * @ORM\GeneratedValue
  48.      * @ORM\Column(type="integer")
  49.      * @Groups({"produit:read"})
  50.      */
  51.     private $id;
  52.     /**
  53.      * @ORM\Column(type="string", length=255)
  54.      * @Groups({"produit:read","produit:write"})
  55.      */
  56.     private $LIBELLE;
  57.     /**
  58.      * @ORM\Column(type="float")
  59.      * @Groups({"produit:read","produit:write"})
  60.      */
  61.     private $PRIX;
  62.     /**
  63.      * @ORM\ManyToOne(targetEntity=TrCategorie::class, inversedBy="trProduits")
  64.      * @ORM\JoinColumn(nullable=false)
  65.      * @Groups({"produit:read","produit:write"})
  66.      */
  67.     private $CATEGORIE;
  68.     /**
  69.      * @ORM\OneToMany(targetEntity=TrDetailsVente::class, mappedBy="PRODUIT")
  70.      */
  71.     private $trDetailsVentes;
  72.     /**
  73.      * @ORM\OneToMany(targetEntity=TrStocks::class, mappedBy="PRODUIT")
  74.      */
  75.     private $trStocks;
  76.     /**
  77.      * @ORM\OneToMany(targetEntity=TrDetailsCommande::class, mappedBy="PRODUIT")
  78.      */
  79.     private $trDetailsCommandes;
  80.     /**
  81.      * @ORM\Column(type="string", length=255)
  82.      * @Groups({"produit:read","produit:write"})
  83.      */
  84.     private $IMAGE;
  85.     /**
  86.      * @ORM\OneToMany(targetEntity=TrDetailPanier::class, mappedBy="Produit")
  87.      */
  88.     private $trDetailPaniers;
  89.     /**
  90.      * @ORM\Column(type="string", length=255, nullable=true)
  91.      * @Groups({"produit:read","produit:write"})
  92.      */
  93.     private $Description;
  94.     /**
  95.      * @ORM\Column(type="string", length=255)
  96.      * @Groups({"produit:read","produit:write"})
  97.      */
  98.     private $CATEGORIES;
  99.     /**
  100.      * @ORM\Column(type="boolean")
  101.      * @Groups({"produit:read","produit:write"})
  102.      */
  103.     private $VEDETTE;
  104.     /**
  105.      * @ORM\Column(type="string", length=255, nullable=true)
  106.      * @Groups({"produit:read","produit:write"})
  107.      */
  108.     private $ALIAS;
  109.     /**
  110.      * @ORM\OneToMany(targetEntity=TrCoeur::class, mappedBy="PRODUIT")
  111.      */
  112.     private $trCoeurs;
  113.     /**
  114.      * @ORM\OneToMany(targetEntity=TrGrosseCommande::class, mappedBy="PRODUIT")
  115.      */
  116.     private $trGrosseCommandes;
  117.     /**
  118.      * @ORM\ManyToOne(targetEntity=TrTypeproduit::class, inversedBy="trProduits")
  119.      * @ORM\JoinColumn(nullable=false)
  120.      */
  121.     private $TYPEPRODUIT;
  122.     /**
  123.      * @ORM\OneToMany(targetEntity=TrProduitsMasse::class, mappedBy="Produit_id")
  124.      */
  125.     private $trProduitsMasses;
  126.     /**
  127.      * @ORM\OneToMany(targetEntity=TrImage::class, mappedBy="produit", cascade={"persist"})
  128.      * @ORM\OrderBy({"isPrincipale" = "DESC", "ordre" = "ASC", "id" = "ASC"})
  129.      */
  130.     private $trImages;
  131.     /**
  132.      * @ORM\OneToMany(targetEntity=TrCommandeSansCompte::class, mappedBy="produit_id")
  133.      */
  134.     private $trCommandeSansComptes;
  135.     /**
  136.      * @ORM\Column(name="promo_active", type="boolean", options={"default": false})
  137.      * @Groups({"produit:read","produit:write"})
  138.      */
  139.     private $promoActive = false;
  140.     /**
  141.      * @ORM\Column(name="prix_promo", type="float", nullable=true)
  142.      * @Groups({"produit:read","produit:write"})
  143.      * @Assert\GreaterThanOrEqual(value=0)
  144.      */
  145.     private $prixPromo;
  146.     /**
  147.      * @ORM\Column(name="promo_date_debut", type="datetime", nullable=true)
  148.      * @Groups({"produit:read","produit:write"})
  149.      */
  150.     private $promoDateDebut;
  151.     /**
  152.      * @ORM\Column(name="promo_date_fin", type="datetime", nullable=true)
  153.      * @Groups({"produit:read","produit:write"})
  154.      */
  155.     private $promoDateFin;
  156.     /**
  157.      * @ORM\OneToMany(targetEntity=KitPromotionnelItem::class, mappedBy="produit")
  158.      */
  159.     private $kitPromotionnelItems;
  160.     public function __construct()
  161.     {
  162.         $this->trDetailsVentes = new ArrayCollection();
  163.         $this->trStocks = new ArrayCollection();
  164.         $this->trDetailsCommandes = new ArrayCollection();
  165.         $this->trDetailPaniers = new ArrayCollection();
  166.         $this->trCoeurs = new ArrayCollection();
  167.         $this->trGrosseCommandes = new ArrayCollection();
  168.         $this->trProduitsMasses = new ArrayCollection();
  169.         $this->trImages = new ArrayCollection();
  170.         $this->trCommandeSansComptes = new ArrayCollection();
  171.         $this->kitPromotionnelItems = new ArrayCollection();
  172.     }
  173.     public function getId(): ?int
  174.     {
  175.         return $this->id;
  176.     }
  177.     public function getLIBELLE(): ?string
  178.     {
  179.         return $this->LIBELLE;
  180.     }
  181.     public function setLIBELLE(string $LIBELLE): self
  182.     {
  183.         $this->LIBELLE = $LIBELLE;
  184.         return $this;
  185.     }
  186.     public function getPRIX(): ?float
  187.     {
  188.         return $this->PRIX;
  189.     }
  190.     public function setPRIX(float $PRIX): self
  191.     {
  192.         $this->PRIX = $PRIX;
  193.         return $this;
  194.     }
  195.     public function getCATEGORIE(): ?TrCategorie
  196.     {
  197.         return $this->CATEGORIE;
  198.     }
  199.     public function setCATEGORIE(?TrCategorie $CATEGORIE): self
  200.     {
  201.         $this->CATEGORIE = $CATEGORIE;
  202.         return $this;
  203.     }
  204.     /**
  205.      * @return Collection<int, TrDetailsVente>
  206.      */
  207.     public function getTrDetailsVentes(): Collection
  208.     {
  209.         return $this->trDetailsVentes;
  210.     }
  211.     public function addTrDetailsVente(TrDetailsVente $trDetailsVente): self
  212.     {
  213.         if (!$this->trDetailsVentes->contains($trDetailsVente)) {
  214.             $this->trDetailsVentes[] = $trDetailsVente;
  215.             $trDetailsVente->setPRODUIT($this);
  216.         }
  217.         return $this;
  218.     }
  219.     public function removeTrDetailsVente(TrDetailsVente $trDetailsVente): self
  220.     {
  221.         if ($this->trDetailsVentes->removeElement($trDetailsVente)) {
  222.             // set the owning side to null (unless already changed)
  223.             if ($trDetailsVente->getPRODUIT() === $this) {
  224.                 $trDetailsVente->setPRODUIT(null);
  225.             }
  226.         }
  227.         return $this;
  228.     }
  229.     /**
  230.      * @return Collection<int, TrStocks>
  231.      */
  232.     public function getTrStocks(): Collection
  233.     {
  234.         return $this->trStocks;
  235.     }
  236.     public function addTrStock(TrStocks $trStock): self
  237.     {
  238.         if (!$this->trStocks->contains($trStock)) {
  239.             $this->trStocks[] = $trStock;
  240.             $trStock->setPRODUIT($this);
  241.         }
  242.         return $this;
  243.     }
  244.     public function removeTrStock(TrStocks $trStock): self
  245.     {
  246.         if ($this->trStocks->removeElement($trStock)) {
  247.             // set the owning side to null (unless already changed)
  248.             if ($trStock->getPRODUIT() === $this) {
  249.                 $trStock->setPRODUIT(null);
  250.             }
  251.         }
  252.         return $this;
  253.     }
  254.     /**
  255.      * @return Collection<int, TrDetailsCommande>
  256.      */
  257.     public function getTrDetailsCommandes(): Collection
  258.     {
  259.         return $this->trDetailsCommandes;
  260.     }
  261.     public function addTrDetailsCommande(TrDetailsCommande $trDetailsCommande): self
  262.     {
  263.         if (!$this->trDetailsCommandes->contains($trDetailsCommande)) {
  264.             $this->trDetailsCommandes[] = $trDetailsCommande;
  265.             $trDetailsCommande->setPRODUIT($this);
  266.         }
  267.         return $this;
  268.     }
  269.     public function removeTrDetailsCommande(TrDetailsCommande $trDetailsCommande): self
  270.     {
  271.         if ($this->trDetailsCommandes->removeElement($trDetailsCommande)) {
  272.             // set the owning side to null (unless already changed)
  273.             if ($trDetailsCommande->getPRODUIT() === $this) {
  274.                 $trDetailsCommande->setPRODUIT(null);
  275.             }
  276.         }
  277.         return $this;
  278.     }
  279.     public function getIMAGE(): ?string
  280.     {
  281.         return $this->IMAGE;
  282.     }
  283.     public function setIMAGE(string $IMAGE): self
  284.     {
  285.         $this->IMAGE = $IMAGE;
  286.         return $this;
  287.     }
  288.     /**
  289.      * @return Collection<int, TrDetailPanier>
  290.      */
  291.     public function getTrDetailPaniers(): Collection
  292.     {
  293.         return $this->trDetailPaniers;
  294.     }
  295.     public function addTrDetailPanier(TrDetailPanier $trDetailPanier): self
  296.     {
  297.         if (!$this->trDetailPaniers->contains($trDetailPanier)) {
  298.             $this->trDetailPaniers[] = $trDetailPanier;
  299.             $trDetailPanier->setProduit($this);
  300.         }
  301.         return $this;
  302.     }
  303.     public function removeTrDetailPanier(TrDetailPanier $trDetailPanier): self
  304.     {
  305.         if ($this->trDetailPaniers->removeElement($trDetailPanier)) {
  306.             // set the owning side to null (unless already changed)
  307.             if ($trDetailPanier->getProduit() === $this) {
  308.                 $trDetailPanier->setProduit(null);
  309.             }
  310.         }
  311.         return $this;
  312.     }
  313.     public function getDescription(): ?string
  314.     {
  315.         return $this->Description;
  316.     }
  317.     public function setDescription(?string $Description): self
  318.     {
  319.         $this->Description = $Description;
  320.         return $this;
  321.     }
  322.     public function getCATEGORIES(): ?string
  323.     {
  324.         return $this->CATEGORIES;
  325.     }
  326.     public function setCATEGORIES(string $CATEGORIES): self
  327.     {
  328.         $this->CATEGORIES = $CATEGORIES;
  329.         return $this;
  330.     }
  331.     public function __toString()
  332.     {
  333.         return $this->LIBELLE."(".$this->Description." )";
  334.     }
  335.     public function isVEDETTE(): ?bool
  336.     {
  337.         return $this->VEDETTE;
  338.     }
  339.     public function setVEDETTE(bool $VEDETTE): self
  340.     {
  341.         $this->VEDETTE = $VEDETTE;
  342.         return $this;
  343.     }
  344.     public function getALIAS(): ?string
  345.     {
  346.         return $this->ALIAS;
  347.     }
  348.     public function setALIAS(?string $ALIAS): self
  349.     {
  350.         $this->ALIAS = $ALIAS;
  351.         return $this;
  352.     }
  353.     /**
  354.      * @return Collection<int, TrCoeur>
  355.      */
  356.     public function getTrCoeurs(): Collection
  357.     {
  358.         return $this->trCoeurs;
  359.     }
  360.     public function addTrCoeur(TrCoeur $trCoeur): self
  361.     {
  362.         if (!$this->trCoeurs->contains($trCoeur)) {
  363.             $this->trCoeurs[] = $trCoeur;
  364.             $trCoeur->setPRODUIT($this);
  365.         }
  366.         return $this;
  367.     }
  368.     public function removeTrCoeur(TrCoeur $trCoeur): self
  369.     {
  370.         if ($this->trCoeurs->removeElement($trCoeur)) {
  371.             // set the owning side to null (unless already changed)
  372.             if ($trCoeur->getPRODUIT() === $this) {
  373.                 $trCoeur->setPRODUIT(null);
  374.             }
  375.         }
  376.         return $this;
  377.     }
  378.     /**
  379.      * @return Collection<int, TrGrosseCommande>
  380.      */
  381.     public function getTrGrosseCommandes(): Collection
  382.     {
  383.         return $this->trGrosseCommandes;
  384.     }
  385.     public function addTrGrosseCommande(TrGrosseCommande $trGrosseCommande): self
  386.     {
  387.         if (!$this->trGrosseCommandes->contains($trGrosseCommande)) {
  388.             $this->trGrosseCommandes[] = $trGrosseCommande;
  389.             $trGrosseCommande->setPRODUIT($this);
  390.         }
  391.         return $this;
  392.     }
  393.     public function removeTrGrosseCommande(TrGrosseCommande $trGrosseCommande): self
  394.     {
  395.         if ($this->trGrosseCommandes->removeElement($trGrosseCommande)) {
  396.             // set the owning side to null (unless already changed)
  397.             if ($trGrosseCommande->getPRODUIT() === $this) {
  398.                 $trGrosseCommande->setPRODUIT(null);
  399.             }
  400.         }
  401.         return $this;
  402.     }
  403.     public function getTYPEPRODUIT(): ?TrTypeproduit
  404.     {
  405.         return $this->TYPEPRODUIT;
  406.     }
  407.     public function setTYPEPRODUIT(?TrTypeproduit $TYPEPRODUIT): self
  408.     {
  409.         $this->TYPEPRODUIT = $TYPEPRODUIT;
  410.         return $this;
  411.     }
  412.     /**
  413.      * @return Collection<int, TrProduitsMasse>
  414.      */
  415.     public function getTrProduitsMasses(): Collection
  416.     {
  417.         return $this->trProduitsMasses;
  418.     }
  419.     public function addTrProduitsMass(TrProduitsMasse $trProduitsMass): self
  420.     {
  421.         if (!$this->trProduitsMasses->contains($trProduitsMass)) {
  422.             $this->trProduitsMasses[] = $trProduitsMass;
  423.             $trProduitsMass->setProduitId($this);
  424.         }
  425.         return $this;
  426.     }
  427.     public function removeTrProduitsMass(TrProduitsMasse $trProduitsMass): self
  428.     {
  429.         if ($this->trProduitsMasses->removeElement($trProduitsMass)) {
  430.             // set the owning side to null (unless already changed)
  431.             if ($trProduitsMass->getProduitId() === $this) {
  432.                 $trProduitsMass->setProduitId(null);
  433.             }
  434.         }
  435.         return $this;
  436.     }
  437.     /**
  438.      * @return Collection<int, TrImage>
  439.      */
  440.     public function getTrImages(): Collection
  441.     {
  442.         return $this->trImages;
  443.     }
  444.     public function addTrImage(TrImage $trImage): self
  445.     {
  446.         if (!$this->trImages->contains($trImage)) {
  447.             $this->trImages[] = $trImage;
  448.             $trImage->setProduit($this);
  449.         }
  450.         return $this;
  451.     }
  452.     public function removeTrImage(TrImage $trImage): self
  453.     {
  454.         if ($this->trImages->removeElement($trImage)) {
  455.             if ($trImage->getProduit() === $this) {
  456.                 $trImage->setProduit(null);
  457.             }
  458.         }
  459.         return $this;
  460.     }
  461.     /**
  462.      * @Groups({"produit:read"})
  463.      * @SerializedName("images")
  464.      */
  465.     public function getImages(): array
  466.     {
  467.         $images = array();
  468.         foreach ($this->trImages as $image) {
  469.             if ($image instanceof TrImage && $image->isActif()) {
  470.                 $images[] = $image;
  471.             }
  472.         }
  473.         usort($images, static function (TrImage $a, TrImage $b): int {
  474.             if ((bool) $a->isPrincipale() !== (bool) $b->isPrincipale()) {
  475.                 return $a->isPrincipale() ? -1 : 1;
  476.             }
  477.             $ordreCompare = ((int) $a->getOrdre()) <=> ((int) $b->getOrdre());
  478.             if (0 !== $ordreCompare) {
  479.                 return $ordreCompare;
  480.             }
  481.             return ((int) $a->getId()) <=> ((int) $b->getId());
  482.         });
  483.         $payload = array();
  484.         foreach (array_slice($images, 0, TrImage::MAX_IMAGES_PER_PRODUCT) as $image) {
  485.             $payload[] = $image->toApiArray();
  486.         }
  487.         if ([] === $payload && $this->getIMAGE()) {
  488.             $payload[] = array(
  489.                 'id' => null,
  490.                 'url' => $this->buildLegacyImageUrl($this->getIMAGE()),
  491.                 'imagePath' => $this->getIMAGE(),
  492.                 'imageName' => $this->getIMAGE(),
  493.                 'ordre' => 1,
  494.                 'isPrincipale' => true,
  495.             );
  496.         }
  497.         return $payload;
  498.     }
  499.     private function buildLegacyImageUrl(string $image): string
  500.     {
  501.         $image = trim($image);
  502.         if (preg_match('/^https?:\/\//i', $image)) {
  503.             return $image;
  504.         }
  505.         if (0 === strpos($image, '/')) {
  506.             return $image;
  507.         }
  508.         if (0 === strpos($image, 'uploads/')) {
  509.             return '/'.$image;
  510.         }
  511.         return '/uploads/brochures/'.$image;
  512.     }
  513.     /**
  514.      * @return Collection<int, TrCommandeSansCompte>
  515.      */
  516.     public function getTrCommandeSansComptes(): Collection
  517.     {
  518.         return $this->trCommandeSansComptes;
  519.     }
  520.     public function addTrCommandeSansCompte(TrCommandeSansCompte $trCommandeSansCompte): self
  521.     {
  522.         if (!$this->trCommandeSansComptes->contains($trCommandeSansCompte)) {
  523.             $this->trCommandeSansComptes[] = $trCommandeSansCompte;
  524.             $trCommandeSansCompte->setProduitId($this);
  525.         }
  526.         return $this;
  527.     }
  528.     public function removeTrCommandeSansCompte(TrCommandeSansCompte $trCommandeSansCompte): self
  529.     {
  530.         if ($this->trCommandeSansComptes->removeElement($trCommandeSansCompte)) {
  531.             // set the owning side to null (unless already changed)
  532.             if ($trCommandeSansCompte->getProduitId() === $this) {
  533.                 $trCommandeSansCompte->setProduitId(null);
  534.             }
  535.         }
  536.         return $this;
  537.     }
  538.     public function isPromoActive(): ?bool
  539.     {
  540.         return $this->promoActive;
  541.     }
  542.     public function setPromoActive(bool $promoActive): self
  543.     {
  544.         $this->promoActive = $promoActive;
  545.         return $this;
  546.     }
  547.     public function getPrixPromo(): ?float
  548.     {
  549.         return $this->prixPromo;
  550.     }
  551.     public function setPrixPromo(?float $prixPromo): self
  552.     {
  553.         $this->prixPromo = $prixPromo;
  554.         return $this;
  555.     }
  556.     public function getPromoDateDebut(): ?\DateTimeInterface
  557.     {
  558.         return $this->promoDateDebut;
  559.     }
  560.     public function setPromoDateDebut(?\DateTimeInterface $promoDateDebut): self
  561.     {
  562.         $this->promoDateDebut = $promoDateDebut;
  563.         return $this;
  564.     }
  565.     public function getPromoDateFin(): ?\DateTimeInterface
  566.     {
  567.         return $this->promoDateFin;
  568.     }
  569.     public function setPromoDateFin(?\DateTimeInterface $promoDateFin): self
  570.     {
  571.         $this->promoDateFin = $promoDateFin;
  572.         return $this;
  573.     }
  574.     public function hasPromotion(?\DateTimeInterface $referenceDate = null): bool
  575.     {
  576.         if (!$this->promoActive || null === $this->prixPromo) {
  577.             return false;
  578.         }
  579.         if (null === $referenceDate) {
  580.             $referenceDate = new \DateTimeImmutable();
  581.         }
  582.         $promoDateDebut = $this->getPromoDateDebutReference();
  583.         $promoDateFin = $this->getPromoDateFinReference();
  584.         if (null !== $promoDateDebut && $referenceDate < $promoDateDebut) {
  585.             return false;
  586.         }
  587.         if (null !== $promoDateFin && $referenceDate > $promoDateFin) {
  588.             return false;
  589.         }
  590.         return $this->prixPromo <= $this->PRIX;
  591.     }
  592.     public function getPrixActuel(?\DateTimeInterface $referenceDate = null): ?float
  593.     {
  594.         if ($this->hasPromotion($referenceDate)) {
  595.             return $this->prixPromo;
  596.         }
  597.         return $this->PRIX;
  598.     }
  599.     public function getPrixBarre(?\DateTimeInterface $referenceDate = null): ?float
  600.     {
  601.         if (!$this->hasPromotion($referenceDate)) {
  602.             return null;
  603.         }
  604.         return $this->PRIX;
  605.     }
  606.     public function getPourcentageReduction(?\DateTimeInterface $referenceDate = null): ?int
  607.     {
  608.         if (!$this->hasPromotion($referenceDate) || $this->PRIX <= 0) {
  609.             return null;
  610.         }
  611.         return (int) round((($this->PRIX - $this->prixPromo) / $this->PRIX) * 100);
  612.     }
  613.     public function isPromotionPlanifiee(): bool
  614.     {
  615.         return $this->promoActive && null !== $this->prixPromo;
  616.     }
  617.     private function getPromoDateDebutReference(): ?\DateTimeInterface
  618.     {
  619.         if (null === $this->promoDateDebut) {
  620.             return null;
  621.         }
  622.         return clone $this->promoDateDebut;
  623.     }
  624.     private function getPromoDateFinReference(): ?\DateTimeInterface
  625.     {
  626.         if (null === $this->promoDateFin) {
  627.             return null;
  628.         }
  629.         $promoDateFin = clone $this->promoDateFin;
  630.         if ('00:00:00' === $promoDateFin->format('H:i:s')) {
  631.             $promoDateFin->setTime(23, 59, 59);
  632.         }
  633.         return $promoDateFin;
  634.     }
  635.     /**
  636.      * @return Collection<int, KitPromotionnelItem>
  637.      */
  638.     public function getKitPromotionnelItems(): Collection
  639.     {
  640.         return $this->kitPromotionnelItems;
  641.     }
  642.     public function addKitPromotionnelItem(KitPromotionnelItem $kitPromotionnelItem): self
  643.     {
  644.         if (!$this->kitPromotionnelItems->contains($kitPromotionnelItem)) {
  645.             $this->kitPromotionnelItems[] = $kitPromotionnelItem;
  646.             $kitPromotionnelItem->setProduit($this);
  647.         }
  648.         return $this;
  649.     }
  650.     public function removeKitPromotionnelItem(KitPromotionnelItem $kitPromotionnelItem): self
  651.     {
  652.         if ($this->kitPromotionnelItems->removeElement($kitPromotionnelItem)) {
  653.             if ($kitPromotionnelItem->getProduit() === $this) {
  654.                 $kitPromotionnelItem->setProduit(null);
  655.             }
  656.         }
  657.         return $this;
  658.     }
  659.     /**
  660.      * @Assert\Callback
  661.      */
  662.     public function validatePromotion(ExecutionContextInterface $context, $payload): void
  663.     {
  664.         if ($this->promoActive && null === $this->prixPromo) {
  665.             $context->buildViolation('Le prix promotionnel est obligatoire quand la promotion est active.')
  666.                 ->atPath('prixPromo')
  667.                 ->addViolation();
  668.         }
  669.         if (null !== $this->prixPromo && null !== $this->PRIX && $this->prixPromo > $this->PRIX) {
  670.             $context->buildViolation('Le prix promotionnel doit etre inferieur ou egal au prix normal.')
  671.                 ->atPath('prixPromo')
  672.                 ->addViolation();
  673.         }
  674.         if (null !== $this->promoDateDebut && null !== $this->promoDateFin && $this->promoDateDebut > $this->promoDateFin) {
  675.             $context->buildViolation('La date de fin de promotion doit etre posterieure a la date de debut.')
  676.                 ->atPath('promoDateFin')
  677.                 ->addViolation();
  678.         }
  679.     }
  680. }