src/Entity/Product/Product.php line 34

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 Arobases\SyliusTransporterLabelGenerationPlugin\Entity\HsCodeTrait;
  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\Collection;
  17. use Doctrine\ORM\Mapping as ORM;
  18. use Setono\SyliusCalloutPlugin\Model\CalloutsAwareTrait as SetonoSyliusCalloutCalloutsAwareTrait;
  19. use Setono\SyliusCalloutPlugin\Model\ProductInterface as SetonoSyliusCalloutProductInterface;
  20. use Sylius\Component\Core\Model\ImageInterface;
  21. use Sylius\Component\Core\Model\Product as BaseProduct;
  22. use Sylius\Component\Core\Model\ProductImageInterface;
  23. use Sylius\Component\Product\Model\ProductTranslationInterface;
  24. use Sylius\Component\Resource\Model\ArchivableTrait;
  25. /**
  26.  * @ORM\Entity
  27.  * @ORM\Table(name="sylius_product")
  28.  */
  29. class Product extends BaseProduct implements SetonoSyliusCalloutProductInterfaceReferenceableInterfaceRichSnippetSubjectInterfaceProductBundlesAwareInterfaceProductInterface
  30. {
  31.     use RichSnippetProductSubjectTrait;
  32.     use ReferenceableTrait;
  33.     use ArchivableTrait;
  34.     use HsCodeTrait;
  35.     use SetonoSyliusCalloutCalloutsAwareTrait {
  36.         SetonoSyliusCalloutCalloutsAwareTrait::__construct as private __calloutsTraitConstruct;
  37.     }
  38.     use ProductBundlesAwareTrait;
  39.     /** @var string|null */
  40.     protected $variantSelectionMethod self::VARIANT_SELECTION_MATCH;
  41.     public function __construct()
  42.     {
  43.         $this->__calloutsTraitConstruct();
  44.         parent::__construct();
  45.     }
  46.     /**
  47.      * @ORM\Column(name="old_id", type="integer", nullable=true)
  48.      */
  49.     private ?int $oldId;
  50.     /**
  51.      * @var ProductBundleInterface
  52.      * @ORM\OneToOne(
  53.      *     targetEntity="BitBag\SyliusProductBundlePlugin\Entity\ProductBundleInterface",
  54.      *     mappedBy="product",
  55.      *     cascade={"all"},)
  56.      */
  57.     protected $productBundle;
  58.     /**
  59.      * @ORM\ManyToOne(targetEntity="App\Entity\Brand\Brand", cascade={"persist"}, fetch="EAGER", inversedBy="products")
  60.      * @ORM\JoinColumn(name="brand_id", referencedColumnName="id", onDelete="SET NULL")
  61.      */
  62.     protected ?Brand $brand null;
  63.     /**
  64.      * @var \DateTimeInterface|null
  65.      *
  66.      * @ORM\Column(name="archived_at", type="datetime", nullable=true)
  67.      */
  68.     protected $archivedAt;
  69.     /**
  70.      * @ORM\ManyToOne(targetEntity="App\Entity\Supplier\Supplier", inversedBy="Product")
  71.      * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  72.      */
  73.     protected ?Supplier $supplier null;
  74.     /**
  75.      * @ORM\Column(name="is_digital_product", type="boolean", options={"default" : 0} )
  76.      */
  77.     private bool $isDigitalProduct false;
  78.     protected function createReferenceableContent(): ReferenceableInterface
  79.     {
  80.         return new SEOContent();
  81.     }
  82.     protected function createTranslation(): ProductTranslationInterface
  83.     {
  84.         return new ProductTranslation();
  85.     }
  86.     public function getSupplier(): ?Supplier
  87.     {
  88.         return $this->supplier;
  89.     }
  90.     public function setSupplier(?Supplier $supplier): void
  91.     {
  92.         $this->supplier $supplier;
  93.     }
  94.     public function getRichSnippetSubjectParent(): ?RichSnippetSubjectInterface
  95.     {
  96.         return $this->getMainTaxon();
  97.     }
  98.     public function getRichSnippetSubjectType(): string
  99.     {
  100.         return 'product';
  101.     }
  102.     public function getBrand(): ?Brand
  103.     {
  104.         return $this->brand;
  105.     }
  106.     public function setBrand(?Brand $brand): void
  107.     {
  108.         $this->brand $brand;
  109.     }
  110.     /**
  111.      * @return bool
  112.      */
  113.     public function isDigitalProduct(): bool
  114.     {
  115.         return $this->isDigitalProduct;
  116.     }
  117.     /**
  118.      * @param bool $isDigitalProduct
  119.      */
  120.     public function setIsDigitalProduct(bool $isDigitalProduct): void
  121.     {
  122.         $this->isDigitalProduct $isDigitalProduct;
  123.     }
  124.     /**
  125.      * @return int|null
  126.      */
  127.     public function getOldId(): ?int
  128.     {
  129.         return $this->oldId;
  130.     }
  131.     /**
  132.      * @param int|null $oldId
  133.      */
  134.     public function setOldId(?int $oldId): void
  135.     {
  136.         $this->oldId $oldId;
  137.     }
  138.     public function getImagesWithoutOneType(?string $type "digital") : Collection
  139.     {
  140.         return $this->images->filter(function (ImageInterface $image) use ($type): bool {
  141.             return $image->getType() !== $type && $image->getType() !== "ia";
  142.         });
  143.     }
  144.     public function getOneImageWithType(?string $type 'ia'): ?ImageInterface
  145.     {
  146.         $image $this->images->filter(function (ImageInterface $image) use ($type): bool {
  147.             return $image->getType() === $type;
  148.         })->first();
  149.         return $image ?: null;
  150.     }
  151.     public function getImagesByPosition(): array
  152.     {
  153.         $images $this->getImages()->toArray();
  154.         usort($images, static function (ProductImageInterface $aProductImageInterface $b): int {
  155.             return $a->getPosition() <=> $b->getPosition();
  156.         });
  157.         return $images;
  158.     }
  159. }