vendor/bitbag/elasticsearch-plugin/src/EventListener/OrderProductsListener.php line 36

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\EventListener;
  11. use BitBag\SyliusElasticsearchPlugin\Refresher\ResourceRefresherInterface;
  12. use FOS\ElasticaBundle\Persister\ObjectPersisterInterface;
  13. use Sylius\Component\Core\Model\OrderInterface;
  14. use Sylius\Component\Core\Model\OrderItemInterface;
  15. use Symfony\Component\EventDispatcher\GenericEvent;
  16. use Webmozart\Assert\Assert;
  17. final class OrderProductsListener
  18. {
  19.     private ResourceRefresherInterface $resourceRefresher;
  20.     private ObjectPersisterInterface $productPersister;
  21.     public function __construct(
  22.         ResourceRefresherInterface $resourceRefresher,
  23.         ObjectPersisterInterface $productPersister
  24.     ) {
  25.         $this->resourceRefresher $resourceRefresher;
  26.         $this->productPersister $productPersister;
  27.     }
  28.     public function updateOrderProducts(GenericEvent $event): void
  29.     {
  30.         $order $event->getSubject();
  31.         Assert::isInstanceOf($orderOrderInterface::class);
  32.         /** @var OrderItemInterface $orderItem */
  33.         foreach ($order->getItems() as $orderItem) {
  34.             $this->resourceRefresher->refresh($orderItem->getProduct(), $this->productPersister);
  35.         }
  36.     }
  37. }