<?php
namespace App\Entity\Product;
use App\Entity\Packing;
use App\Repository\Product\ProductRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ProductRepository::class)
*/
class Product
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=1024)
*/
private $name;
/**
* @ORM\ManyToOne(targetEntity=Packing::class, inversedBy="products")
* @ORM\JoinColumn(nullable=false)
*/
private $packing;
/**
* @ORM\Column(type="float")
*/
private $totalWeight;
/**
* @ORM\OneToMany(targetEntity=Item::class, mappedBy="product", cascade={"persist","remove"})
*/
private $items;
public function __construct()
{
$this->items = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getPacking(): ?Packing
{
return $this->packing;
}
public function setPacking(?Packing $packing): self
{
$this->packing = $packing;
return $this;
}
public function getTotalWeight(): ?float
{
return $this->totalWeight;
}
public function setTotalWeight(float $totalWeight): self
{
$this->totalWeight = $totalWeight;
return $this;
}
/**
* @return Collection<int, Item>
*/
public function getItems(): Collection
{
return $this->items;
}
public function addItem(Item $item): self
{
if (!$this->items->contains($item)) {
$this->items[] = $item;
$item->setProduct($this);
}
return $this;
}
public function removeItem(Item $item): self
{
if ($this->items->removeElement($item)) {
// set the owning side to null (unless already changed)
if ($item->getProduct() === $this) {
$item->setProduct(null);
}
}
return $this;
}
}