src/Entity/Product.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProductRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  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=255)
  21.      */
  22.     private $name;
  23.     /**
  24.      * @ORM\ManyToOne(targetEntity=Color::class, inversedBy="products")
  25.      */
  26.     private $color;
  27.     /**
  28.      * @ORM\ManyToOne(targetEntity=Grade::class, inversedBy="products")
  29.      */
  30.     private $grade;
  31.     /**
  32.      * @ORM\ManyToOne(targetEntity=Keyboard::class, inversedBy="products")
  33.      */
  34.     private $keyboard;
  35.     /**
  36.      * @ORM\ManyToOne(targetEntity=Capacity::class, inversedBy="products")
  37.      */
  38.     private $capacity;
  39.     /**
  40.      * @ORM\ManyToOne(targetEntity=Model::class, inversedBy="products")
  41.      * @ORM\JoinColumn(nullable=false)
  42.      */
  43.     private $model;
  44.     /**
  45.      * @ORM\Column(type="integer")
  46.      */
  47.     private $qty;
  48.     /**
  49.      * @ORM\OneToMany(targetEntity=Stock::class, mappedBy="product")
  50.      */
  51.     private $stocks;
  52.     /**
  53.      * @ORM\Column(type="string", length=32)
  54.      */
  55.     private $sku;
  56.     /**
  57.      * @ORM\Column(type="integer", nullable=true)
  58.      */
  59.     private $price;
  60.     /**
  61.      * @ORM\Column(type="text", nullable=true)
  62.      */
  63.     private $description;
  64.     /**
  65.      * @ORM\Column(type="string", length=16, nullable=true)
  66.      */
  67.     private $channel;
  68.     public function __construct()
  69.     {
  70.         $this->stocks = new ArrayCollection();
  71.     }
  72.     public function __toString() {
  73.         return $this->getName();
  74.     }
  75.     public function getId(): ?int
  76.     {
  77.         return $this->id;
  78.     }
  79.     public function getName(): ?string
  80.     {
  81.         return $this->name;
  82.     }
  83.     public function setName(string $name): self
  84.     {
  85.         $this->name $name;
  86.         return $this;
  87.     }
  88.     public function getColor(): ?Color
  89.     {
  90.         return $this->color;
  91.     }
  92.     public function setColor(?Color $color): self
  93.     {
  94.         $this->color $color;
  95.         return $this;
  96.     }
  97.     public function getGrade(): ?Grade
  98.     {
  99.         return $this->grade;
  100.     }
  101.     public function setGrade(?Grade $grade): self
  102.     {
  103.         $this->grade $grade;
  104.         return $this;
  105.     }
  106.     public function getKeyboard(): ?Keyboard
  107.     {
  108.         return $this->keyboard;
  109.     }
  110.     public function setKeyboard(?Keyboard $keyboard): self
  111.     {
  112.         $this->keyboard $keyboard;
  113.         return $this;
  114.     }
  115.     public function getCapacity(): ?Capacity
  116.     {
  117.         return $this->capacity;
  118.     }
  119.     public function setCapacity(?Capacity $capacity): self
  120.     {
  121.         $this->capacity $capacity;
  122.         return $this;
  123.     }
  124.     public function getModel(): ?Model
  125.     {
  126.         return $this->model;
  127.     }
  128.     public function setModel(?Model $model): self
  129.     {
  130.         $this->model $model;
  131.         return $this;
  132.     }
  133.     public function getQty(): ?int
  134.     {
  135.         return $this->qty;
  136.     }
  137.     public function setQty(int $qty): self
  138.     {
  139.         $this->qty $qty;
  140.         return $this;
  141.     }
  142.     /**
  143.      * @return Collection<int, Stock>
  144.      */
  145.     public function getStocks(): Collection
  146.     {
  147.         return $this->stocks;
  148.     }
  149.     public function getSku(): ?string
  150.     {
  151.         return $this->sku;
  152.     }
  153.     public function setSku(string $sku): self
  154.     {
  155.         $this->sku $sku;
  156.         return $this;
  157.     }
  158.     public function getPrice(): ?int
  159.     {
  160.         return $this->price;
  161.     }
  162.     public function setPrice(?int $price): self
  163.     {
  164.         $this->price $price;
  165.         return $this;
  166.     }
  167.     public function getDescription(): ?string
  168.     {
  169.         return $this->description;
  170.     }
  171.     public function setDescription(?string $description): self
  172.     {
  173.         $this->description $description;
  174.         return $this;
  175.     }
  176.     public function getChannel(): ?string
  177.     {
  178.         return $this->channel;
  179.     }
  180.     public function setChannel(?string $channel): self
  181.     {
  182.         $this->channel $channel;
  183.         return $this;
  184.     }
  185.     public function addStock(Stock $stock): static
  186.     {
  187.         if (!$this->stocks->contains($stock)) {
  188.             $this->stocks->add($stock);
  189.             $stock->setProduct($this);
  190.         }
  191.         return $this;
  192.     }
  193.     public function removeStock(Stock $stock): static
  194.     {
  195.         if ($this->stocks->removeElement($stock)) {
  196.             // set the owning side to null (unless already changed)
  197.             if ($stock->getProduct() === $this) {
  198.                 $stock->setProduct(null);
  199.             }
  200.         }
  201.         return $this;
  202.     }
  203. }