src/Component/Elasticsearch/PropertyBuilder/FeaturedPropertyBuilder.php line 19

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace BitBag\OpenMarketplace\Component\Elasticsearch\PropertyBuilder;
  4. use BitBag\OpenMarketplace\Component\Product\Entity\ProductInterface;
  5. use BitBag\SyliusElasticsearchPlugin\PropertyBuilder\AbstractBuilder;
  6. use Elastica\Document;
  7. use FOS\ElasticaBundle\Event\PostTransformEvent;
  8. final class FeaturedPropertyBuilder extends AbstractBuilder
  9. {
  10.     public function __construct(
  11.         private string $featuredProperty
  12.     ) {
  13.     }
  14.     public function consumeEvent(PostTransformEvent $event): void
  15.     {
  16.         $this->buildProperty(
  17.             $event,
  18.             ProductInterface::class,
  19.             function (ProductInterface $productDocument $document): void {
  20.                 $document->set(
  21.                     $this->featuredProperty,
  22.                     (int) $product->isFeatured(),
  23.                 );
  24.             }
  25.         );
  26.     }
  27. }