custom/plugins/ZeobvGetNotified/src/FlowBuilder/Action/NotificationAction.php line 49

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Zeobv\GetNotified\FlowBuilder\Action;
  4. use Shopware\Core\Content\Flow\Dispatching\Action\FlowAction;
  5. use Shopware\Core\Content\MailTemplate\Exception\MailEventConfigurationException;
  6. use Shopware\Core\Content\MailTemplate\Exception\SalesChannelNotFoundException;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
  8. use Shopware\Core\Framework\Event\FlowEvent;
  9. use Symfony\Component\Messenger\MessageBusInterface;
  10. use Symfony\Contracts\EventDispatcher\Event;
  11. use Zeobv\GetNotified\FlowBuilder\Aware\ProductAware;
  12. use Zeobv\GetNotified\MessageBus\Message\NotificationActionMessage;
  13. use Zeobv\GetNotified\Service\StockSubscriptionService;
  14. class NotificationAction extends FlowAction
  15. {
  16.     protected StockSubscriptionService $stockSubscriptionService;
  17.     private MessageBusInterface $messageBus;
  18.     public function __construct(
  19.         StockSubscriptionService $stockSubscriptionService,
  20.         MessageBusInterface $messageBus
  21.     ) {
  22.         $this->stockSubscriptionService $stockSubscriptionService;
  23.         $this->messageBus $messageBus;
  24.     }
  25.     public static function getName(): string
  26.     {
  27.         // your own action name
  28.         return 'zeobv-get-notified.action.send.notification';
  29.     }
  30.     public static function getSubscribedEvents(): array
  31.     {
  32.         return [
  33.             self::getName() => 'handle',
  34.         ];
  35.     }
  36.     public function requirements(): array
  37.     {
  38.         return [ProductAware::class];
  39.     }
  40.     public function handle(Event $event): void
  41.     {
  42.         if (!$event instanceof FlowEvent) {
  43.             return;
  44.         }
  45.         $notificationEvent $event->getEvent();
  46.         if (!$notificationEvent instanceof ProductAware) {
  47.             throw new \Exception('Not an instance of ProductAware, instance given ' . \get_class($notificationEvent));
  48.         }
  49.         $productId $notificationEvent->getProductId();
  50.         $this->messageBus->dispatch(new NotificationActionMessage($productId$event->getConfig()));
  51.     }
  52. }