<?php
namespace App\Entity\Produit;
use App\Entity\Order\OrderLineOption;
use App\Repository\OptionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Produit\Produit;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
#[ORM\Entity(repositoryClass: OptionRepository::class)]
#[ORM\Table(name: '`option`')]
class Option implements TranslatableInterface
{
use TranslatableTrait;
#[Assert\Valid]
protected $translations;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'decimal', precision: 10, scale: 2, nullable:true)]
private $priceHt;
#[ORM\Column(type: 'decimal', precision: 10, scale: 2, nullable:true)]
private $priceTtc;
#[ORM\Column(type: 'decimal', precision: 10, scale: 2, nullable:true)]
private $taxRate;
#[ORM\ManyToMany(targetEntity: Produit::class, mappedBy: 'produitOption')]
private $produits;
#[ORM\OneToMany(mappedBy: 'opt', targetEntity: OrderLineOption::class)]
private Collection $orderLineOptions;
public function __construct()
{
$this->produits = new ArrayCollection();
$this->orderLineOptions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getPrice(): ?string
{
return $this->priceTtc;
}
public function getPriceHt()
{
return $this->priceHt;
}
public function setPriceHt($priceHt): self
{
$this->priceHt = $priceHt;
return $this;
}
public function getPriceTtc()
{
return $this->priceTtc;
}
public function setPriceTtc($priceTtc): self
{
$this->priceTtc = $priceTtc;
return $this;
}
public function getTaxRate()
{
return $this->taxRate;
}
public function setTaxRate($taxRate): self
{
$this->taxRate = $taxRate;
return $this;
}
/**
* @return Collection<int, Produit>
*/
public function getProduits(): Collection
{
return $this->produits;
}
public function addProduit(Produit $produit): self
{
if (!$this->produits->contains($produit)) {
$this->produits[] = $produit;
$produit->addProduitOption($this);
}
return $this;
}
public function removeProduit(Produit $produit): self
{
if ($this->produits->removeElement($produit)) {
$produit->removeProduitOption($this);
}
return $this;
}
public function getName(): ?string
{
if($this->translate()->getName()) {
return $this->translate()->getName();
}
return '';
}
/**
* @return Collection<int, OrderLineOption>
*/
public function getOrderLineOptions(): Collection
{
return $this->orderLineOptions;
}
public function addOrderLineOption(OrderLineOption $orderLineOption): static
{
if (!$this->orderLineOptions->contains($orderLineOption)) {
$this->orderLineOptions->add($orderLineOption);
$orderLineOption->setOpt($this);
}
return $this;
}
public function removeOrderLineOption(OrderLineOption $orderLineOption): static
{
if ($this->orderLineOptions->removeElement($orderLineOption)) {
// set the owning side to null (unless already changed)
if ($orderLineOption->getOpt() === $this) {
$orderLineOption->setOpt(null);
}
}
return $this;
}
public function __toString()
{
return $this->translate()->getName();
}
}