<?php
declare(strict_types=1);
namespace Zeobv\GetNotified\FlowBuilder\Action;
use Shopware\Core\Content\Flow\Dispatching\Action\FlowAction;
use Shopware\Core\Content\MailTemplate\Exception\MailEventConfigurationException;
use Shopware\Core\Content\MailTemplate\Exception\SalesChannelNotFoundException;
use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
use Shopware\Core\Framework\Event\FlowEvent;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Contracts\EventDispatcher\Event;
use Zeobv\GetNotified\FlowBuilder\Aware\ProductAware;
use Zeobv\GetNotified\MessageBus\Message\NotificationActionMessage;
use Zeobv\GetNotified\Service\StockSubscriptionService;
class NotificationAction extends FlowAction
{
protected StockSubscriptionService $stockSubscriptionService;
private MessageBusInterface $messageBus;
public function __construct(
StockSubscriptionService $stockSubscriptionService,
MessageBusInterface $messageBus
) {
$this->stockSubscriptionService = $stockSubscriptionService;
$this->messageBus = $messageBus;
}
public static function getName(): string
{
// your own action name
return 'zeobv-get-notified.action.send.notification';
}
public static function getSubscribedEvents(): array
{
return [
self::getName() => 'handle',
];
}
public function requirements(): array
{
return [ProductAware::class];
}
public function handle(Event $event): void
{
if (!$event instanceof FlowEvent) {
return;
}
$notificationEvent = $event->getEvent();
if (!$notificationEvent instanceof ProductAware) {
throw new \Exception('Not an instance of ProductAware, instance given ' . \get_class($notificationEvent));
}
$productId = $notificationEvent->getProductId();
$this->messageBus->dispatch(new NotificationActionMessage($productId, $event->getConfig()));
}
}