src/Entity/Product.php line 16
<?phpnamespace App\Entity;use App\Repository\ProductRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;use Symfony\Component\Serializer\Annotation\Groups;use Symfony\Component\Uid\Uuid;#[ORM\Entity(repositoryClass: ProductRepository::class)]// #[UniqueEntity(['whitelabel', 'name'], message: 'Record with this name already exists.')]class Product{#[ORM\Id]#[ORM\Column(type: 'uuid', unique: true)]#[Groups(['BASE'])]private ?string $id = null;#[ORM\Column(length: 255)]private ?string $name = null;#[ORM\Column(length: 255, nullable: true)]private ?string $nameEn = null;/*** @phpstan-ignore-next-line*/#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: '2')]private ?float $price = null;#[ORM\Column(type: Types::DATETIME_MUTABLE)]private ?\DateTimeInterface $createDate = null;#[ORM\ManyToOne(inversedBy: 'products')]#[ORM\JoinColumn(nullable: false)]private ?Whitelabel $whitelabel = null;#[ORM\ManyToOne(inversedBy: 'products')]#[ORM\JoinColumn(nullable: false)]private ?User $creatorUser = null;#[ORM\ManyToMany(targetEntity: Component::class, inversedBy: 'products')]private Collection $components;#[ORM\ManyToMany(targetEntity: Menu::class, mappedBy: 'products')]private Collection $menus;#[ORM\Column(nullable: true)]private ?int $weight = null;#[ORM\ManyToOne(inversedBy: 'products')]#[ORM\JoinColumn(nullable: true)]private ?ProductCategory $category = null;#[ORM\ManyToMany(targetEntity: Allergen::class, inversedBy: 'products')]private Collection $allergens;public function __construct(){$this->id = Uuid::v4();$this->components = new ArrayCollection();$this->menus = new ArrayCollection();$this->allergens = new ArrayCollection();}public function __toString(){$name = $this->getName();if (!empty($this->getCategory())) {$name = $name.' - '.$this->getCategory()->getName();}$name = $name.' ('.$this->getPrice().'лв.)';return $name;}public function getId(): ?string{return $this->id;}public function getName(): ?string{return $this->name;}public function setName(string $name): self{$this->name = $name;return $this;}public function getNameEn(): ?string{return $this->nameEn;}public function setNameEn(?string $nameEn): self{$this->nameEn = $nameEn;return $this;}public function getPrice(): ?float{return $this->price;}public function getFormattedPrice(){return $this->price.' USD';}public function setPrice(float $price): self{$this->price = $price;return $this;}public function getCreateDate(): ?\DateTimeInterface{return $this->createDate;}public function setCreateDate(\DateTimeInterface $createDate): self{$this->createDate = $createDate;return $this;}public function getWhitelabel(): ?Whitelabel{return $this->whitelabel;}public function setWhitelabel(?Whitelabel $whitelabel): self{$this->whitelabel = $whitelabel;return $this;}public function getCreatorUser(): ?User{return $this->creatorUser;}public function setCreatorUser(?User $creatorUser): self{$this->creatorUser = $creatorUser;return $this;}/*** @return Collection<int, Component>*/public function getComponents(): Collection{return $this->components;}public function addComponent(Component $component): self{if (!$this->components->contains($component)) {$this->components->add($component);}return $this;}public function removeComponent(Component $component): self{$this->components->removeElement($component);return $this;}/*** @return Collection<int, Menu>*/public function getMenus(): Collection{return $this->menus;}public function addMenu(Menu $menu): self{if (!$this->menus->contains($menu)) {$this->menus->add($menu);$menu->addProduct($this);}return $this;}public function removeMenu(Menu $menu): self{if ($this->menus->removeElement($menu)) {$menu->removeProduct($this);}return $this;}public function getWeight(): ?int{return $this->weight;}public function setWeight(?int $weight): self{$this->weight = $weight;return $this;}public function getCategory(): ?ProductCategory{return $this->category;}public function setCategory(?ProductCategory $category): self{$this->category = $category;return $this;}/*** @return Collection<int, Allergen>*/public function getAllergens(): Collection{return $this->allergens;}public function addAllergen(Allergen $allergen): self{if (!$this->allergens->contains($allergen)) {$this->allergens->add($allergen);}return $this;}public function removeAllergen(Allergen $allergen): self{$this->components->removeElement($allergen);return $this;}}