vendor/bitbag/elasticsearch-plugin/src/PropertyBuilder/ProductTaxonsBuilder.php line 32

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 BitBag\SyliusElasticsearchPlugin\PropertyBuilder\Mapper\ProductTaxonsMapperInterface;
  12. use Elastica\Document;
  13. use FOS\ElasticaBundle\Event\PostTransformEvent;
  14. use Sylius\Component\Core\Model\ProductInterface;
  15. final class ProductTaxonsBuilder extends AbstractBuilder
  16. {
  17.     private ProductTaxonsMapperInterface $productTaxonsMapper;
  18.     private string $taxonsProperty;
  19.     public function __construct(ProductTaxonsMapperInterface $productTaxonsMapperstring $taxonsProperty)
  20.     {
  21.         $this->productTaxonsMapper $productTaxonsMapper;
  22.         $this->taxonsProperty $taxonsProperty;
  23.     }
  24.     public function consumeEvent(PostTransformEvent $event): void
  25.     {
  26.         $this->buildProperty(
  27.             $event,
  28.             ProductInterface::class,
  29.             function (ProductInterface $productDocument $document): void {
  30.                 $taxons $this->productTaxonsMapper->mapToUniqueCodes($product);
  31.                 $document->set($this->taxonsProperty$taxons);
  32.             }
  33.         );
  34.     }
  35. }