vendor/bitbag/elasticsearch-plugin/src/PropertyBuilder/ProductTaxonPositionPropertyBuilder.php line 29

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\PropertyNameResolver\ConcatedNameResolverInterface;
  12. use Elastica\Document;
  13. use FOS\ElasticaBundle\Event\PostTransformEvent;
  14. use Sylius\Component\Core\Model\ProductInterface;
  15. final class ProductTaxonPositionPropertyBuilder extends AbstractBuilder
  16. {
  17.     private ConcatedNameResolverInterface $taxonPositionNameResolver;
  18.     public function __construct(ConcatedNameResolverInterface $taxonPositionNameResolver)
  19.     {
  20.         $this->taxonPositionNameResolver $taxonPositionNameResolver;
  21.     }
  22.     public function consumeEvent(PostTransformEvent $event): void
  23.     {
  24.         $this->buildProperty(
  25.             $event,
  26.             ProductInterface::class,
  27.             function (ProductInterface $productDocument $document): void {
  28.                 foreach ($product->getProductTaxons() as $taxon) {
  29.                     $document->set(
  30.                         $this->taxonPositionNameResolver->resolvePropertyName($taxon->getTaxon()->getCode()),
  31.                         $taxon->getPosition()
  32.                     );
  33.                 }
  34.             }
  35.         );
  36.     }
  37. }