custom/static-plugins/relewise/src/Subscriber/IntegrationSubscriber.php line 45

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Wexo\Relewise\Subscriber;
  3. use Shopware\Core\Content\Category\Event\CategoryIndexerEvent;
  4. use Shopware\Core\Content\Product\Events\ProductIndexerEvent;
  5. use Shopware\Core\Framework\Feature;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\Messenger\MessageBusInterface;
  8. use Wexo\Relewise\Component\RelewiseContentMessage;
  9. use Wexo\Relewise\Component\RelewiseProductMessage;
  10. use Wexo\Relewise\Service\Model\Export\Content\ContentUpdate;
  11. use Wexo\Relewise\Service\Model\Export\Product\ProductUpdate;
  12. class IntegrationSubscriber implements EventSubscriberInterface
  13. {
  14.     /**
  15.      * @var MessageBusInterface
  16.      */
  17.     private MessageBusInterface $bus;
  18.     /**
  19.      * @param MessageBusInterface $bus
  20.      */
  21.     public function __construct(
  22.         MessageBusInterface $bus
  23.     ) {
  24.         $this->bus $bus;
  25.     }
  26.     /**
  27.      * @return string[]
  28.      */
  29.     public static function getSubscribedEvents(): array
  30.     {
  31.         return [
  32.             ProductIndexerEvent::class => 'onProductIndexer',
  33.             CategoryIndexerEvent::class => 'onCategoryIndexer'
  34.         ];
  35.     }
  36.     /**
  37.      * @param ProductIndexerEvent $event
  38.      */
  39.     public function onProductIndexer(ProductIndexerEvent $event): void
  40.     {
  41.         if (Feature::isActive('v6.5.0.0')) {
  42.             $ids $event->getIds();
  43.         } else {
  44.             $ids array_merge($event->getIds(), $event->getChildrenIds(), $event->getParentIds());
  45.         }
  46.         $this->bus->dispatch(
  47.             new RelewiseProductMessage(
  48.                 new ProductUpdate(),
  49.                 array_unique($ids),
  50.                 $event->getContext()
  51.             )
  52.         );
  53.     }
  54.     /**
  55.      * @param CategoryIndexerEvent $event
  56.      */
  57.     public function onCategoryIndexer(CategoryIndexerEvent $event): void
  58.     {
  59.         $this->bus->dispatch(
  60.             new RelewiseContentMessage(
  61.                 new ContentUpdate(),
  62.                 array_unique($event->getIds()),
  63.                 $event->getContext()
  64.             )
  65.         );
  66.     }
  67. }