<?php
declare(strict_types=1);
namespace App\Entity\Product;
use App\Entity\Brand\Brand;
use App\Entity\Configurator\ConfiguratorOption;
use App\Entity\Supplier\Supplier;
use BitBag\SyliusProductBundlePlugin\Entity\ProductBundleInterface;
use BitBag\SyliusProductBundlePlugin\Entity\ProductBundlesAwareInterface;
use BitBag\SyliusProductBundlePlugin\Entity\ProductBundlesAwareTrait;
use BitBag\SyliusProductBundlePlugin\Entity\ProductInterface;
use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\ReferenceableInterface;
use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\ReferenceableTrait;
use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\RichSnippetProductSubjectTrait;
use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\RichSnippetSubjectInterface;
use Dedi\SyliusSEOPlugin\Entity\SEOContent;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use MonsieurBiz\SyliusSearchPlugin\Entity\Product\SearchableInterface;
use MonsieurBiz\SyliusSearchPlugin\Model\Product\SearchableTrait;
use Setono\SyliusCalloutPlugin\Model\CalloutsAwareTrait as SetonoSyliusCalloutCalloutsAwareTrait;
use Setono\SyliusCalloutPlugin\Model\ProductInterface as SetonoSyliusCalloutProductInterface;
use Sylius\Component\Core\Model\Product as BaseProduct;
use Sylius\Component\Product\Model\ProductTranslationInterface;
use Sylius\Component\Resource\Model\ArchivableTrait;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* @ORM\Entity
* @ORM\Table(name="sylius_product")
*/
class Product extends BaseProduct implements SetonoSyliusCalloutProductInterface, ReferenceableInterface, RichSnippetSubjectInterface, ProductBundlesAwareInterface, ProductInterface, SearchableInterface
{
use RichSnippetProductSubjectTrait;
use ReferenceableTrait;
use ArchivableTrait;
use SetonoSyliusCalloutCalloutsAwareTrait {
SetonoSyliusCalloutCalloutsAwareTrait::__construct as private __calloutsTraitConstruct;
}
use ProductBundlesAwareTrait;
use ReferenceableTrait {
getMetadataTitle as getBaseMetadataTitle;
getMetadataDescription as getBaseMetadataDescription;
}
use SearchableTrait;
public function __construct()
{
$this->__calloutsTraitConstruct();
parent::__construct();
$this->files = new ArrayCollection();
$this->configuratorOptions = new ArrayCollection();
$this->pictograms = new ArrayCollection();
}
/**
* @ORM\Column(name="file_path", type="string", nullable=true)
*/
private ?string $filePath = null;
private ?UploadedFile $file = null;
/**
* @var ProductBundleInterface
* @ORM\OneToOne(
* targetEntity="BitBag\SyliusProductBundlePlugin\Entity\ProductBundleInterface",
* mappedBy="product",
* cascade={"all"},)
*/
protected $productBundle;
/**
* @ORM\OneToMany(targetEntity=Pictogram::class, mappedBy="product", cascade={"persist"})
*/
protected Collection $pictograms;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Product\ProductFile", inversedBy="products")
* @ORM\JoinTable(
* name="app_product_product_file",
* joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")},
* inverseJoinColumns={@ORM\JoinColumn(name="product_file_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")}
* )
*/
protected $files;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Configurator\ConfiguratorOption", inversedBy="products")
* @ORM\JoinTable(
* name="app_product_configurator_option",
* joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")},
* inverseJoinColumns={@ORM\JoinColumn(name="configurator_option_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")}
* )
*/
protected Collection $configuratorOptions;
public function getMetadataTitle(): ?string
{
if (is_null($this->getReferenceableContent()->getMetadataTitle()))
{
return $this->getName();
}
return $this->getBaseMetadataTitle();
}
public function getMetadataDescription(): ?string
{
if (!empty($this->getBaseMetadataDescription()))
{
return $this->getBaseMetadataDescription();
}
return $this->getMetaDescription();
}
protected function createReferenceableContent(): ReferenceableInterface
{
return new SEOContent();
}
protected function createTranslation(): ProductTranslationInterface
{
return new ProductTranslation();
}
/**
* @var \DateTimeInterface|null
*
* @ORM\Column(name="archived_at", type="datetime", nullable=true)
*/
protected $archivedAt;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Supplier\Supplier", inversedBy="Product")
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
protected ?Supplier $supplier = null;
public function getSupplier(): ?Supplier
{
return $this->supplier;
}
public function setSupplier(?Supplier $supplier): void
{
$this->supplier = $supplier;
}
public function getRichSnippetSubjectParent(): ?RichSnippetSubjectInterface
{
return $this->getMainTaxon();
}
public function getRichSnippetSubjectType(): string
{
return 'product';
}
/**
* @var Brand
*
* @ORM\ManyToOne(targetEntity="App\Entity\Brand\Brand", cascade={"persist"}, fetch="EAGER", inversedBy="products")
* @ORM\JoinColumn(name="brand_id", referencedColumnName="id", onDelete="SET NULL", nullable=true)
*/
protected ?Brand $brand = null;
/**
* @return Brand|null
*/
public function getBrand(): ?Brand
{
return $this->brand;
}
/**
* @param Brand|null $brand
*/
public function setBrand(?Brand $brand): void
{
$this->brand = $brand;
}
/**
* @return string|null
*/
public function getFilePath(): ?string
{
return $this->filePath;
}
/**
* @param string|null $filePath
*/
public function setFilePath(?string $filePath): void
{
$this->filePath = $filePath;
}
/**
* @return UploadedFile|null
*/
public function getFile(): ?UploadedFile
{
return $this->file;
}
/**
* @param UploadedFile|null $file
*/
public function setFile(?UploadedFile $file): void
{
$this->file = $file;
}
/**
* @return \DateTimeInterface|null
*/
public function getArchivedAt(): ?\DateTimeInterface
{
return $this->archivedAt;
}
/**
* @param \DateTimeInterface|null $archivedAt
*/
public function setArchivedAt(?\DateTimeInterface $archivedAt): void
{
$this->archivedAt = $archivedAt;
}
public function getFiles(): Collection
{
return $this->files;
}
public function addFile(ProductFile $file)
{
if ($this->files->contains($file)) {
return;
}
$this->files->add($file);
$file->addProduct($this);
}
public function removeFile(ProductFile $file)
{
if (!$this->files->contains($file)) {
return;
}
$this->files->removeElement($file);
$file->removeProduct($this);
}
public function getPictograms(): Collection
{
return $this->pictograms;
}
public function addPictogram(Pictogram $pictogram)
{
if ($this->pictograms->contains($pictogram)) {
return;
}
$this->pictograms->add($pictogram);
$pictogram->setProduct($this);
}
public function removePictogram(Pictogram $pictogram)
{
if (!$this->pictograms->contains($pictogram)) {
return;
}
$this->pictograms->removeElement($pictogram);
}
public function getConfiguratorOptions(): Collection
{
return $this->configuratorOptions;
}
public function addConfiguratorOption(ConfiguratorOption $configuratorOption)
{
if ($this->configuratorOptions->contains($configuratorOption)) {
return;
}
$this->configuratorOptions->add($configuratorOption);
$configuratorOption->addProduct($this);
}
public function removeConfiguratorOption(ConfiguratorOption $configuratorOption)
{
if (!$this->configuratorOptions->contains($configuratorOption)) {
return;
}
$this->configuratorOptions->removeElement($configuratorOption);
$configuratorOption->removeProduct($this);
}
}