src/Flexy/StockBundle/Entity/Article.php line 14

  1. <?php
  2. namespace App\Flexy\StockBundle\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Entity\Product\Product;
  5. use App\Flexy\StockBundle\Repository\ArticleRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. #[ApiResource]
  10. #[ORM\Entity(repositoryClassArticleRepository::class)]
  11. class Article extends Product
  12. {
  13.     #[ORM\OneToMany(targetEntityStock::class, mappedBy'article')]
  14.     private \Doctrine\Common\Collections\Collection|array $stocks;
  15.     #[ORM\Column(type'float'nullabletrue)]
  16.     private ?float $regularPrice null;
  17.     public function __construct()
  18.     {
  19.         parent::__construct();
  20.         $this->stocks = new ArrayCollection();
  21.     }
  22.     /**
  23.      * @return Collection|Stock[]
  24.      */
  25.     public function getStocks(): Collection
  26.     {
  27.         return $this->stocks;
  28.     }
  29.     public function addStock(Stock $stock): self
  30.     {
  31.         if (!$this->stocks->contains($stock)) {
  32.             $this->stocks[] = $stock;
  33.             $stock->setArticle($this);
  34.         }
  35.         return $this;
  36.     }
  37.     public function removeStock(Stock $stock): self
  38.     {
  39.         if ($this->stocks->removeElement($stock)) {
  40.             // set the owning side to null (unless already changed)
  41.             if ($stock->getArticle() === $this) {
  42.                 $stock->setArticle(null);
  43.             }
  44.         }
  45.         return $this;
  46.     }
  47.     public function getRegularPrice(): ?float
  48.     {
  49.         return $this->regularPrice;
  50.     }
  51.     public function setRegularPrice(?float $regularPrice): self
  52.     {
  53.         $this->regularPrice $regularPrice;
  54.         return $this;
  55.     }
  56. }