src/Entity/Product/Product.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Product;
  3. use App\Entity\Packing;
  4. use App\Repository\Product\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.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=1024)
  21.      */
  22.     private $name;
  23.     /**
  24.      * @ORM\ManyToOne(targetEntity=Packing::class, inversedBy="products")
  25.      * @ORM\JoinColumn(nullable=false)
  26.      */
  27.     private $packing;
  28.     /**
  29.      * @ORM\Column(type="float")
  30.      */
  31.     private $totalWeight;
  32.     /**
  33.      * @ORM\OneToMany(targetEntity=Item::class, mappedBy="product", cascade={"persist","remove"})
  34.      */
  35.     private $items;
  36.     public function __construct()
  37.     {
  38.         $this->items = new ArrayCollection();
  39.     }
  40.     public function getId(): ?int
  41.     {
  42.         return $this->id;
  43.     }
  44.     public function getName(): ?string
  45.     {
  46.         return $this->name;
  47.     }
  48.     public function setName(string $name): self
  49.     {
  50.         $this->name $name;
  51.         return $this;
  52.     }
  53.     public function getPacking(): ?Packing
  54.     {
  55.         return $this->packing;
  56.     }
  57.     public function setPacking(?Packing $packing): self
  58.     {
  59.         $this->packing $packing;
  60.         return $this;
  61.     }
  62.     public function getTotalWeight(): ?float
  63.     {
  64.         return $this->totalWeight;
  65.     }
  66.     public function setTotalWeight(float $totalWeight): self
  67.     {
  68.         $this->totalWeight $totalWeight;
  69.         return $this;
  70.     }
  71.     /**
  72.      * @return Collection<int, Item>
  73.      */
  74.     public function getItems(): Collection
  75.     {
  76.         return $this->items;
  77.     }
  78.     public function addItem(Item $item): self
  79.     {
  80.         if (!$this->items->contains($item)) {
  81.             $this->items[] = $item;
  82.             $item->setProduct($this);
  83.         }
  84.         return $this;
  85.     }
  86.     public function removeItem(Item $item): self
  87.     {
  88.         if ($this->items->removeElement($item)) {
  89.             // set the owning side to null (unless already changed)
  90.             if ($item->getProduct() === $this) {
  91.                 $item->setProduct(null);
  92.             }
  93.         }
  94.         return $this;
  95.     }
  96. }