src/Entity/Product/Product.php line 36

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Product;
  4. use App\Entity\Brand\Brand;
  5. use App\Entity\Configurator\ConfiguratorOption;
  6. use App\Entity\Supplier\Supplier;
  7. use BitBag\SyliusProductBundlePlugin\Entity\ProductBundleInterface;
  8. use BitBag\SyliusProductBundlePlugin\Entity\ProductBundlesAwareInterface;
  9. use BitBag\SyliusProductBundlePlugin\Entity\ProductBundlesAwareTrait;
  10. use BitBag\SyliusProductBundlePlugin\Entity\ProductInterface;
  11. use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\ReferenceableInterface;
  12. use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\ReferenceableTrait;
  13. use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\RichSnippetProductSubjectTrait;
  14. use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\RichSnippetSubjectInterface;
  15. use Dedi\SyliusSEOPlugin\Entity\SEOContent;
  16. use Doctrine\Common\Collections\ArrayCollection;
  17. use Doctrine\Common\Collections\Collection;
  18. use Doctrine\ORM\Mapping as ORM;
  19. use MonsieurBiz\SyliusSearchPlugin\Entity\Product\SearchableInterface;
  20. use MonsieurBiz\SyliusSearchPlugin\Model\Product\SearchableTrait;
  21. use Setono\SyliusCalloutPlugin\Model\CalloutsAwareTrait as SetonoSyliusCalloutCalloutsAwareTrait;
  22. use Setono\SyliusCalloutPlugin\Model\ProductInterface as SetonoSyliusCalloutProductInterface;
  23. use Sylius\Component\Core\Model\Product as BaseProduct;
  24. use Sylius\Component\Product\Model\ProductTranslationInterface;
  25. use Sylius\Component\Resource\Model\ArchivableTrait;
  26. use Symfony\Component\HttpFoundation\File\UploadedFile;
  27. /**
  28.  * @ORM\Entity
  29.  * @ORM\Table(name="sylius_product")
  30.  */
  31. class Product extends BaseProduct implements SetonoSyliusCalloutProductInterfaceReferenceableInterfaceRichSnippetSubjectInterfaceProductBundlesAwareInterfaceProductInterfaceSearchableInterface
  32. {
  33.     use RichSnippetProductSubjectTrait;
  34.     use ReferenceableTrait;
  35.     use ArchivableTrait;
  36.     use SetonoSyliusCalloutCalloutsAwareTrait {
  37.         SetonoSyliusCalloutCalloutsAwareTrait::__construct as private __calloutsTraitConstruct;
  38.     }
  39.     use ProductBundlesAwareTrait;
  40.     use ReferenceableTrait {
  41.         getMetadataTitle as getBaseMetadataTitle;
  42.         getMetadataDescription as getBaseMetadataDescription;
  43.     }
  44.     use SearchableTrait;
  45.     public function __construct()
  46.     {
  47.         $this->__calloutsTraitConstruct();
  48.         parent::__construct();
  49.         $this->files = new ArrayCollection();
  50.         $this->configuratorOptions = new ArrayCollection();
  51.         $this->pictograms = new ArrayCollection();
  52.     }
  53.     /**
  54.      * @ORM\Column(name="file_path", type="string", nullable=true)
  55.      */
  56.     private ?string $filePath null;
  57.     private ?UploadedFile $file null;
  58.     /**
  59.      * @var ProductBundleInterface
  60.      * @ORM\OneToOne(
  61.      *     targetEntity="BitBag\SyliusProductBundlePlugin\Entity\ProductBundleInterface",
  62.      *     mappedBy="product",
  63.      *     cascade={"all"},)
  64.      */
  65.     protected $productBundle;
  66.     /**
  67.      * @ORM\OneToMany(targetEntity=Pictogram::class, mappedBy="product", cascade={"persist"})
  68.      */
  69.     protected Collection $pictograms;
  70.     /**
  71.      * @ORM\ManyToMany(targetEntity="App\Entity\Product\ProductFile", inversedBy="products")
  72.      * @ORM\JoinTable(
  73.      *      name="app_product_product_file",
  74.      *      joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")},
  75.      *      inverseJoinColumns={@ORM\JoinColumn(name="product_file_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")}
  76.      *      )
  77.      */
  78.     protected $files;
  79.     /**
  80.      * @ORM\ManyToMany(targetEntity="App\Entity\Configurator\ConfiguratorOption", inversedBy="products")
  81.      * @ORM\JoinTable(
  82.      *      name="app_product_configurator_option",
  83.      *      joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")},
  84.      *      inverseJoinColumns={@ORM\JoinColumn(name="configurator_option_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")}
  85.      *      )
  86.      */
  87.     protected Collection $configuratorOptions;
  88.     public function getMetadataTitle(): ?string
  89.     {
  90.         if (is_null($this->getReferenceableContent()->getMetadataTitle()))
  91.         {
  92.             return $this->getName();
  93.         }
  94.         return $this->getBaseMetadataTitle();
  95.     }
  96.     public function getMetadataDescription(): ?string
  97.     {
  98.         if (!empty($this->getBaseMetadataDescription()))
  99.         {
  100.             return $this->getBaseMetadataDescription();
  101.         }
  102.         return $this->getMetaDescription();
  103.     }
  104.     protected function createReferenceableContent(): ReferenceableInterface
  105.     {
  106.         return new SEOContent();
  107.     }
  108.     protected function createTranslation(): ProductTranslationInterface
  109.     {
  110.         return new ProductTranslation();
  111.     }
  112.     /**
  113.      * @var \DateTimeInterface|null
  114.      *
  115.      * @ORM\Column(name="archived_at", type="datetime", nullable=true)
  116.      */
  117.     protected $archivedAt;
  118.     /**
  119.      * @ORM\ManyToOne(targetEntity="App\Entity\Supplier\Supplier", inversedBy="Product")
  120.      * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  121.      */
  122.     protected ?Supplier $supplier null;
  123.     public function getSupplier(): ?Supplier
  124.     {
  125.         return $this->supplier;
  126.     }
  127.     public function setSupplier(?Supplier $supplier): void
  128.     {
  129.         $this->supplier $supplier;
  130.     }
  131.     public function getRichSnippetSubjectParent(): ?RichSnippetSubjectInterface
  132.     {
  133.         return $this->getMainTaxon();
  134.     }
  135.     public function getRichSnippetSubjectType(): string
  136.     {
  137.         return 'product';
  138.     }
  139.     /**
  140.      * @var Brand
  141.      *
  142.      * @ORM\ManyToOne(targetEntity="App\Entity\Brand\Brand", cascade={"persist"}, fetch="EAGER", inversedBy="products")
  143.      * @ORM\JoinColumn(name="brand_id", referencedColumnName="id", onDelete="SET NULL", nullable=true)
  144.      */
  145.     protected ?Brand $brand null;
  146.     /**
  147.      * @return Brand|null
  148.      */
  149.     public function getBrand(): ?Brand
  150.     {
  151.         return $this->brand;
  152.     }
  153.     /**
  154.      * @param Brand|null $brand
  155.      */
  156.     public function setBrand(?Brand $brand): void
  157.     {
  158.         $this->brand $brand;
  159.     }
  160.     /**
  161.      * @return string|null
  162.      */
  163.     public function getFilePath(): ?string
  164.     {
  165.         return $this->filePath;
  166.     }
  167.     /**
  168.      * @param string|null $filePath
  169.      */
  170.     public function setFilePath(?string $filePath): void
  171.     {
  172.         $this->filePath $filePath;
  173.     }
  174.     /**
  175.      * @return UploadedFile|null
  176.      */
  177.     public function getFile(): ?UploadedFile
  178.     {
  179.         return $this->file;
  180.     }
  181.     /**
  182.      * @param UploadedFile|null $file
  183.      */
  184.     public function setFile(?UploadedFile $file): void
  185.     {
  186.         $this->file $file;
  187.     }
  188.     /**
  189.      * @return \DateTimeInterface|null
  190.      */
  191.     public function getArchivedAt(): ?\DateTimeInterface
  192.     {
  193.         return $this->archivedAt;
  194.     }
  195.     /**
  196.      * @param \DateTimeInterface|null $archivedAt
  197.      */
  198.     public function setArchivedAt(?\DateTimeInterface $archivedAt): void
  199.     {
  200.         $this->archivedAt $archivedAt;
  201.     }
  202.     public function getFiles(): Collection
  203.     {
  204.         return $this->files;
  205.     }
  206.     public function addFile(ProductFile $file)
  207.     {
  208.         if ($this->files->contains($file)) {
  209.             return;
  210.         }
  211.         $this->files->add($file);
  212.         $file->addProduct($this);
  213.     }
  214.     public function removeFile(ProductFile $file)
  215.     {
  216.         if (!$this->files->contains($file)) {
  217.             return;
  218.         }
  219.         $this->files->removeElement($file);
  220.         $file->removeProduct($this);
  221.     }
  222.     public function getPictograms(): Collection
  223.     {
  224.         return $this->pictograms;
  225.     }
  226.     public function addPictogram(Pictogram $pictogram)
  227.     {
  228.         if ($this->pictograms->contains($pictogram)) {
  229.             return;
  230.         }
  231.         $this->pictograms->add($pictogram);
  232.         $pictogram->setProduct($this);
  233.     }
  234.     public function removePictogram(Pictogram $pictogram)
  235.     {
  236.         if (!$this->pictograms->contains($pictogram)) {
  237.             return;
  238.         }
  239.         $this->pictograms->removeElement($pictogram);
  240.     }
  241.     public function getConfiguratorOptions(): Collection
  242.     {
  243.         return $this->configuratorOptions;
  244.     }
  245.     public function addConfiguratorOption(ConfiguratorOption $configuratorOption)
  246.     {
  247.         if ($this->configuratorOptions->contains($configuratorOption)) {
  248.             return;
  249.         }
  250.         $this->configuratorOptions->add($configuratorOption);
  251.         $configuratorOption->addProduct($this);
  252.     }
  253.     public function removeConfiguratorOption(ConfiguratorOption $configuratorOption)
  254.     {
  255.         if (!$this->configuratorOptions->contains($configuratorOption)) {
  256.             return;
  257.         }
  258.         $this->configuratorOptions->removeElement($configuratorOption);
  259.         $configuratorOption->removeProduct($this);
  260.     }
  261. }