src/Entity/Product.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\EntityTrait;
  4. use App\Repository\ProductRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass=ProductRepository::class)
  10.  */
  11. class Product
  12. {
  13.     use EntityTrait{
  14.         EntityTrait::__construct as private __entityConstruct;
  15.     }
  16.     /**
  17.      * @ORM\Column(type="string", length=255)
  18.      */
  19.     private $name;
  20.     /**
  21.      * @ORM\OneToMany(targetEntity=ProductField::class, mappedBy="product", orphanRemoval=true, cascade={"persist"})
  22.      * @ORM\OrderBy({"sortorder" = "ASC"})
  23.      */
  24.     private $productFields;
  25.     public function __construct()
  26.     {
  27.         $this->__entityConstruct();
  28.         $this->productFields = new ArrayCollection();
  29.     }
  30.     public function getName(): ?string
  31.     {
  32.         return $this->name;
  33.     }
  34.     public function setName(string $name): self
  35.     {
  36.         $this->name $name;
  37.         return $this;
  38.     }
  39.     /**
  40.      * @return Collection|ProductField[]
  41.      */
  42.     public function getProductFields(): Collection
  43.     {
  44.         return $this->productFields;
  45.     }
  46.     public function addProductField(ProductField $productField): self
  47.     {
  48.         if (!$this->productFields->contains($productField)) {
  49.             $this->productFields[] = $productField;
  50.             $productField->setProduct($this);
  51.         }
  52.         return $this;
  53.     }
  54.     public function removeProductField(ProductField $productField): self
  55.     {
  56.         if ($this->productFields->removeElement($productField)) {
  57.             // set the owning side to null (unless already changed)
  58.             if ($productField->getProduct() === $this) {
  59.                 $productField->setProduct(null);
  60.             }
  61.         }
  62.         return $this;
  63.     }
  64.     public function __toString(){
  65.         return $this->getName();
  66.     }
  67. }