src/Entity/Product/Product.php line 26

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Product;
  4. use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\ReferenceableInterface;
  5. use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\ReferenceableTrait;
  6. use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\RichSnippetProductSubjectTrait;
  7. use Dedi\SyliusSEOPlugin\Domain\SEO\Adapter\RichSnippetSubjectInterface;
  8. use Dedi\SyliusSEOPlugin\Entity\SEOContent;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Doctrine\ORM\PersistentCollection;
  13. use Sylius\Component\Core\Model\ImageInterface;
  14. use Sylius\Component\Core\Model\Product as BaseProduct;
  15. use Sylius\Component\Product\Model\ProductTranslationInterface;
  16. use Mezcalito\SyliusFileUploadPlugin\Model\FilesAwareInterface;
  17. use Mezcalito\SyliusFileUploadPlugin\Model\FilesAwareTrait;
  18. /**
  19.  * @ORM\Entity
  20.  * @ORM\Table(name="sylius_product")
  21.  */
  22. class Product extends BaseProduct implements FilesAwareInterfaceReferenceableInterfaceRichSnippetSubjectInterface
  23. {
  24.     use ReferenceableTrait {
  25.         getMetadataTitle as getBaseMetadataTitle;
  26.         getMetadataDescription as getBaseMetadataDescription;
  27.     }
  28.     use RichSnippetProductSubjectTrait;
  29.     /**
  30.      * @ORM\OneToMany(targetEntity="ProductFile", mappedBy="owner", orphanRemoval="true", cascade={"all"})
  31.      */
  32.     protected $files;
  33.     //    /**
  34.     //     * @ORM\OrderBy({"position"="ASC"})
  35.     //     */
  36.     //    protected $images;
  37.     /**
  38.      * @var Collection|ImageInterface[]
  39.      * @ORM\OrderBy({"position" = "ASC"})
  40.      * @psalm-var Collection<array-key, ImageInterface>
  41.      */
  42.     protected $images;
  43.     /**
  44.      * @ORM\Column(type="boolean", nullable=true)
  45.      */
  46.     protected ?bool $buildingPermitNotRequired;
  47.     use FilesAwareTrait {
  48.         __construct as private initializeFilesCollection;
  49.     }
  50.     public function __construct()
  51.     {
  52.         parent::__construct();
  53.         $this->files = new ArrayCollection();
  54.         $this->addFile(new ProductFile());
  55.         $this->images = new ArrayCollection();
  56.     }
  57.     /**
  58.      * {@inheritDoc}
  59.      */
  60.     public function getFiles(): Collection
  61.     {
  62.         if (count($this->files) == 0) {
  63.             $this->addFile(new ProductFile());
  64.         }
  65.         return $this->files;
  66.     }
  67.     public function getImages(): Collection
  68.     {
  69.         /** @var PersistentCollection $collection */
  70.         $collection $this->images;
  71.         $values $collection->getValues();
  72.         uasort($values, function($a$b) {
  73.             return $a->getPosition() < $b->getPosition() ? -1;
  74.         });
  75.         $collection->clear();
  76.         foreach ($values as $key => $value) {
  77.             $collection->set($key$value);
  78.         }
  79.         return $collection;
  80.     }
  81.     public function getBuildingPermitNotRequired(): ?bool
  82.     {
  83.         return $this->buildingPermitNotRequired;
  84.     }
  85.     public function setBuildingPermitNotRequired(?bool $buildingPermitNotRequired): void
  86.     {
  87.         $this->buildingPermitNotRequired $buildingPermitNotRequired;
  88.     }
  89.     public function getChannels(): Collection
  90.     {
  91.         return parent::getChannels(); // TODO: Change the autogenerated stub
  92.     }
  93.     public function getRichSnippetSubjectParent(): ?RichSnippetSubjectInterface
  94.     {
  95.         return $this->getMainTaxon();
  96.     }
  97.     public function getRichSnippetSubjectType(): string
  98.     {
  99.         return 'product';
  100.     }
  101.     public function getMetadataTitle(): ?string
  102.     {
  103.         if (is_null($this->getReferenceableContent()->getMetadataTitle())) {
  104.             return $this->getName();
  105.         }
  106.         return $this->getBaseMetadataTitle();
  107.     }
  108.     public function getMetadataDescription(): ?string
  109.     {
  110.         if (is_null($this->getReferenceableContent()->getMetadataDescription())) {
  111.             return $this->getShortDescription();
  112.         }
  113.         return $this->getBaseMetadataDescription();
  114.     }
  115.     protected function createTranslation(): ProductTranslationInterface
  116.     {
  117.         return new ProductTranslation();
  118.     }
  119.     protected function createReferenceableContent(): ReferenceableInterface
  120.     {
  121.         return new SEOContent();
  122.     }
  123. }