<?php
namespace App\Entity;
use App\Entity\Traits\EntityTrait;
use App\Repository\ProductRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ProductRepository::class)
*/
class Product
{
use EntityTrait{
EntityTrait::__construct as private __entityConstruct;
}
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\OneToMany(targetEntity=ProductField::class, mappedBy="product", orphanRemoval=true, cascade={"persist"})
* @ORM\OrderBy({"sortorder" = "ASC"})
*/
private $productFields;
public function __construct()
{
$this->__entityConstruct();
$this->productFields = new ArrayCollection();
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection|ProductField[]
*/
public function getProductFields(): Collection
{
return $this->productFields;
}
public function addProductField(ProductField $productField): self
{
if (!$this->productFields->contains($productField)) {
$this->productFields[] = $productField;
$productField->setProduct($this);
}
return $this;
}
public function removeProductField(ProductField $productField): self
{
if ($this->productFields->removeElement($productField)) {
// set the owning side to null (unless already changed)
if ($productField->getProduct() === $this) {
$productField->setProduct(null);
}
}
return $this;
}
public function __toString(){
return $this->getName();
}
}