<?php
declare(strict_types=1);
namespace App\Entity\Product;
use App\Entity\Brand\Brand;
use App\Entity\Supplier\Supplier;
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 Setono\SyliusCalloutPlugin\Model\CalloutsAwareTrait as SetonoSyliusCalloutCalloutsAwareTrait;
use Setono\SyliusCalloutPlugin\Model\ProductInterface as SetonoSyliusCalloutProductInterface;
use Sylius\Component\Core\Model\Product as BaseProduct;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Product\Model\ProductTranslationInterface;
use Sylius\Component\Resource\Model\ArchivableTrait;
/**
* @ORM\Entity
* @ORM\Table(name="sylius_product")
*/
class Product extends BaseProduct implements SetonoSyliusCalloutProductInterface, ReferenceableInterface, RichSnippetSubjectInterface
{
use RichSnippetProductSubjectTrait;
use ReferenceableTrait;
use ArchivableTrait;
use SetonoSyliusCalloutCalloutsAwareTrait {
SetonoSyliusCalloutCalloutsAwareTrait::__construct as private __calloutsTraitConstruct;
}
public function __construct()
{
$this->__calloutsTraitConstruct();
parent::__construct();
$this->files = new ArrayCollection();
}
public function createReferenceableContent(): ReferenceableInterface
{
return new SEOContent();
}
public 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")
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
protected ?Supplier $supplier = null;
/** @ORM\Column(type="boolean", nullable=true) */
private $newProduct = false;
/** @ORM\Column(type="boolean", options={"default": 1}) */
private $saleable = true;
/**
* @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\Column(name="video_url", type="string", nullable=true) */
private ?string $videoUrl = 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';
}
/**
* @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;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Product\ProductImage", cascade={"persist"}, fetch="EAGER")
* @ORM\JoinColumn(name="main_image_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected ?ProductImage $mainImage = null;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Product\Product", cascade={"persist"})
* @ORM\JoinColumn(name="alternative_product_id", referencedColumnName="id", onDelete="SET NULL", nullable=true)
*/
protected ?ProductInterface $alternativeProduct = null;
public function setId(mixed $id): void
{
$this->id = $id;
}
public function getBrand(): ?Brand
{
return $this->brand;
}
public function setBrand(?Brand $brand): void
{
$this->brand = $brand;
}
public function setReferenceableContent(SEOContent $SEOContent): void
{
$this->referenceableContent = $SEOContent;
}
/**
* Get the value of newProduct.
*/
public function getNewProduct(): bool
{
return $this->newProduct;
}
/**
* Set the value of newProduct.
*
* @return self
*/
public function setNewProduct(bool $newProduct)
{
$this->newProduct = $newProduct;
return $this;
}
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 getMainImage(): ?ProductImage
{
return $this->mainImage;
}
public function setMainImage(?ProductImage $mainImage): void
{
$this->mainImage = $mainImage;
}
public function isSaleable(): bool
{
return $this->saleable;
}
public function setSaleable(bool $saleable): void
{
$this->saleable = $saleable;
}
public function getAlternativeProduct(): ?ProductInterface
{
return $this->alternativeProduct;
}
public function setAlternativeProduct(?ProductInterface $alternativeProduct): void
{
$this->alternativeProduct = $alternativeProduct;
}
public function getVideoUrl(): ?string
{
return $this->videoUrl;
}
public function setVideoUrl(?string $videoUrl): void
{
$this->videoUrl = $videoUrl;
}
}