src/Core/Subscriber/PharmacyCategorySubscriber.php line 35

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Bodymed\Webshop\Core\Subscriber;
  4. use Bodymed\Webshop\Messenger\Messages\PharmacyCategoryConfig\PharmacyCategoryConfigWritten;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\Messenger\MessageBusInterface;
  10. class PharmacyCategorySubscriber implements EventSubscriberInterface
  11. {
  12.     private EntityRepositoryInterface $pharmacyCategoryConfigRepository;
  13.     private MessageBusInterface $messengerAsyncBus;
  14.     public function __construct(
  15.         EntityRepositoryInterface $pharmacyCategoryConfigRepository,
  16.         MessageBusInterface $messengerAsyncBus
  17.     ) {
  18.         $this->pharmacyCategoryConfigRepository $pharmacyCategoryConfigRepository;
  19.         $this->messengerAsyncBus $messengerAsyncBus;
  20.     }
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             'pharmacy_category_config.written' => 'onEntityWritten',
  25.         ];
  26.     }
  27.     public function onEntityWritten(EntityWrittenEvent $event): void
  28.     {
  29.         $context $event->getContext();
  30.         $ids $event->getIds();
  31.         $result $this->pharmacyCategoryConfigRepository->search(new Criteria($ids), $context);
  32.         $this->messengerAsyncBus->dispatch(PharmacyCategoryConfigWritten::create($result->getEntities(), $context));
  33.     }
  34. }