src/Entity/Product/Product.php line 28

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\Supplier\Supplier;
  6. use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\ReferenceableInterface;
  7. use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\ReferenceableTrait;
  8. use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\RichSnippetProductSubjectTrait;
  9. use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\RichSnippetSubjectInterface;
  10. use Dedi\SyliusSEOPlugin\Entity\SEOContent;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Setono\SyliusCalloutPlugin\Model\CalloutsAwareTrait as SetonoSyliusCalloutCalloutsAwareTrait;
  15. use Setono\SyliusCalloutPlugin\Model\ProductInterface as SetonoSyliusCalloutProductInterface;
  16. use Sylius\Component\Core\Model\Product as BaseProduct;
  17. use Sylius\Component\Core\Model\ProductInterface;
  18. use Sylius\Component\Product\Model\ProductTranslationInterface;
  19. use Sylius\Component\Resource\Model\ArchivableTrait;
  20. /**
  21.  * @ORM\Entity
  22.  * @ORM\Table(name="sylius_product")
  23.  */
  24. class Product extends BaseProduct implements SetonoSyliusCalloutProductInterfaceReferenceableInterfaceRichSnippetSubjectInterface
  25. {
  26.     use RichSnippetProductSubjectTrait;
  27.     use ReferenceableTrait;
  28.     use ArchivableTrait;
  29.     use SetonoSyliusCalloutCalloutsAwareTrait {
  30.         SetonoSyliusCalloutCalloutsAwareTrait::__construct as private __calloutsTraitConstruct;
  31.     }
  32.     public function __construct()
  33.     {
  34.         $this->__calloutsTraitConstruct();
  35.         parent::__construct();
  36.         $this->files = new ArrayCollection();
  37.     }
  38.     public function createReferenceableContent(): ReferenceableInterface
  39.     {
  40.         return new SEOContent();
  41.     }
  42.     public function createTranslation(): ProductTranslationInterface
  43.     {
  44.         return new ProductTranslation();
  45.     }
  46.     /**
  47.      * @var \DateTimeInterface|null
  48.      *
  49.      * @ORM\Column(name="archived_at", type="datetime", nullable=true)
  50.      */
  51.     protected $archivedAt;
  52.     /**
  53.      * @ORM\ManyToOne(targetEntity="App\Entity\Supplier\Supplier")
  54.      * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  55.      */
  56.     protected ?Supplier $supplier null;
  57.     /** @ORM\Column(type="boolean", nullable=true) */
  58.     private $newProduct false;
  59.     /** @ORM\Column(type="boolean", options={"default": 1}) */
  60.     private $saleable true;
  61.     /**
  62.      * @ORM\ManyToMany(targetEntity="App\Entity\Product\ProductFile", inversedBy="products")
  63.      * @ORM\JoinTable(
  64.      *      name="app_product_product_file",
  65.      *      joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")},
  66.      *      inverseJoinColumns={@ORM\JoinColumn(name="product_file_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")}
  67.      *      )
  68.      */
  69.     protected $files;
  70.     /** @ORM\Column(name="video_url", type="string", nullable=true) */
  71.     private ?string $videoUrl null;
  72.     public function getSupplier(): ?Supplier
  73.     {
  74.         return $this->supplier;
  75.     }
  76.     public function setSupplier(?Supplier $supplier): void
  77.     {
  78.         $this->supplier $supplier;
  79.     }
  80.     public function getRichSnippetSubjectParent(): ?RichSnippetSubjectInterface
  81.     {
  82.         return $this->getMainTaxon();
  83.     }
  84.     public function getRichSnippetSubjectType(): string
  85.     {
  86.         return 'product';
  87.     }
  88.     /**
  89.      * @ORM\ManyToOne(targetEntity="App\Entity\Brand\Brand", cascade={"persist"}, fetch="EAGER", inversedBy="products")
  90.      * @ORM\JoinColumn(name="brand_id", referencedColumnName="id", onDelete="SET NULL", nullable=true)
  91.      */
  92.     protected ?Brand $brand null;
  93.     /**
  94.      * @ORM\ManyToOne(targetEntity="App\Entity\Product\ProductImage", cascade={"persist"}, fetch="EAGER")
  95.      * @ORM\JoinColumn(name="main_image_id", referencedColumnName="id", onDelete="SET NULL")
  96.      */
  97.     protected ?ProductImage $mainImage null;
  98.     /**
  99.      * @ORM\ManyToOne(targetEntity="App\Entity\Product\Product", cascade={"persist"})
  100.      * @ORM\JoinColumn(name="alternative_product_id", referencedColumnName="id", onDelete="SET NULL", nullable=true)
  101.      */
  102.     protected ?ProductInterface $alternativeProduct null;
  103.     public function setId(mixed $id): void
  104.     {
  105.         $this->id $id;
  106.     }
  107.     public function getBrand(): ?Brand
  108.     {
  109.         return $this->brand;
  110.     }
  111.     public function setBrand(?Brand $brand): void
  112.     {
  113.         $this->brand $brand;
  114.     }
  115.     public function setReferenceableContent(SEOContent $SEOContent): void
  116.     {
  117.         $this->referenceableContent $SEOContent;
  118.     }
  119.     /**
  120.      * Get the value of newProduct.
  121.      */
  122.     public function getNewProduct(): bool
  123.     {
  124.         return $this->newProduct;
  125.     }
  126.     /**
  127.      * Set the value of newProduct.
  128.      *
  129.      * @return self
  130.      */
  131.     public function setNewProduct(bool $newProduct)
  132.     {
  133.         $this->newProduct $newProduct;
  134.         return $this;
  135.     }
  136.     public function getFiles(): Collection
  137.     {
  138.         return $this->files;
  139.     }
  140.     public function addFile(ProductFile $file)
  141.     {
  142.         if ($this->files->contains($file)) {
  143.             return;
  144.         }
  145.         $this->files->add($file);
  146.         $file->addProduct($this);
  147.     }
  148.     public function removeFile(ProductFile $file)
  149.     {
  150.         if (!$this->files->contains($file)) {
  151.             return;
  152.         }
  153.         $this->files->removeElement($file);
  154.         $file->removeProduct($this);
  155.     }
  156.     public function getMainImage(): ?ProductImage
  157.     {
  158.         return $this->mainImage;
  159.     }
  160.     public function setMainImage(?ProductImage $mainImage): void
  161.     {
  162.         $this->mainImage $mainImage;
  163.     }
  164.     public function isSaleable(): bool
  165.     {
  166.         return $this->saleable;
  167.     }
  168.     public function setSaleable(bool $saleable): void
  169.     {
  170.         $this->saleable $saleable;
  171.     }
  172.     public function getAlternativeProduct(): ?ProductInterface
  173.     {
  174.         return $this->alternativeProduct;
  175.     }
  176.     public function setAlternativeProduct(?ProductInterface $alternativeProduct): void
  177.     {
  178.         $this->alternativeProduct $alternativeProduct;
  179.     }
  180.     public function getVideoUrl(): ?string
  181.     {
  182.         return $this->videoUrl;
  183.     }
  184.     public function setVideoUrl(?string $videoUrl): void
  185.     {
  186.         $this->videoUrl $videoUrl;
  187.     }
  188. }