vendor/bitbag/elasticsearch-plugin/src/PropertyBuilder/ChannelsBuilder.php line 28

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file has been created by developers from BitBag.
  4.  * Feel free to contact us once you face any issues or want to start
  5.  * another great project.
  6.  * You can find more information about us on https://bitbag.io and write us
  7.  * an email on hello@bitbag.io.
  8.  */
  9. declare(strict_types=1);
  10. namespace BitBag\SyliusElasticsearchPlugin\PropertyBuilder;
  11. use Elastica\Document;
  12. use FOS\ElasticaBundle\Event\PostTransformEvent;
  13. use Sylius\Component\Core\Model\ProductInterface;
  14. final class ChannelsBuilder extends AbstractBuilder
  15. {
  16.     private string $channelsProperty;
  17.     public function __construct(string $channelsProperty)
  18.     {
  19.         $this->channelsProperty $channelsProperty;
  20.     }
  21.     public function consumeEvent(PostTransformEvent $event): void
  22.     {
  23.         $this->buildProperty(
  24.             $event,
  25.             ProductInterface::class,
  26.             function (ProductInterface $productDocument $document): void {
  27.                 $channels = [];
  28.                 foreach ($product->getChannels() as $channel) {
  29.                     $channels[] = $channel->getCode();
  30.                 }
  31.                 $document->set($this->channelsProperty$channels);
  32.             }
  33.         );
  34.     }
  35. }