<?php
namespace App\Entity;
use App\Repository\PromotionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PromotionRepository::class)]
class Promotion
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column]
private ?float $rate = null;
#[ORM\OneToMany(mappedBy: 'promotion', targetEntity: produitpromotion::class, orphanRemoval: true)]
private Collection $promotions;
public function __construct()
{
$this->promotions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getRate(): ?float
{
// dd($this->rate);
// return $this->rate;
if ($this->rate === null) {
// Retourner une valeur par défaut (par exemple, 0.0) ou gérer l'erreur
return 0.0; // ou retourner null selon le besoin
}
return (float)($this->rate);
}
public function setRate(float $rate): self
{
$this->rate = $rate;
return $this;
}
/**
* @return Collection<int, produitpromotion>
*/
public function getPromotions(): Collection
{
return $this->promotions;
}
public function addPromotion(produitpromotion $promotion): self
{
if (!$this->promotions->contains($promotion)) {
$this->promotions->add($promotion);
$promotion->setPromotion($this);
}
return $this;
}
public function removePromotion(produitpromotion $promotion): self
{
if ($this->promotions->removeElement($promotion)) {
// set the owning side to null (unless already changed)
if ($promotion->getPromotion() === $this) {
$promotion->setPromotion(null);
}
}
return $this;
}
}