vendor/bitbag/elasticsearch-plugin/src/PropertyBuilder/ProductCreatedAtPropertyBuilder.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 ProductCreatedAtPropertyBuilder extends AbstractBuilder
  15. {
  16.     private string $createdAtProperty;
  17.     public function __construct(string $createdAtProperty)
  18.     {
  19.         $this->createdAtProperty $createdAtProperty;
  20.     }
  21.     public function consumeEvent(PostTransformEvent $event): void
  22.     {
  23.         $this->buildProperty(
  24.             $event,
  25.             ProductInterface::class,
  26.             function (ProductInterface $productDocument $document): void {
  27.                 $createdAt = (int) $product->getCreatedAt()->format('U');
  28.                 $document->set($this->createdAtProperty$createdAt);
  29.             }
  30.         );
  31.     }
  32. }