<?php
namespace Nextag\Flow\Flow;
use Exception;
use Shopware\Core\Content\Flow\Dispatching\Action\FlowAction;
use Shopware\Core\Framework\Event\FlowEvent;
use Nextag\Flow\Helper\Log;
class MailAction extends FlowAction
{
private Log $logHelper;
private \Nextag\Mail\Helper\MailGenerator $mailGenerator;
public function __construct(
Log $logHelper,
\Nextag\Mail\Helper\MailGenerator $mailGenerator
)
{
$this->logHelper = $logHelper;
$this->mailGenerator = $mailGenerator;
}
public static function getName(): string
{
return 'action.flow.nextag.mail';
}
public static function getSubscribedEvents(): array
{
return [
self::getName() => 'handle'
];
}
public function requirements(): array
{
return [];
}
public function handle(FlowEvent $event): void
{
$config = $event->getConfig();
$order = null;
$mailEvent = $event->getEvent();
try {
$order = $mailEvent->getOrder();
} catch(Exception $e) {
return;
}
if($order === null) {
return;
}
$this->mailGenerator->sendEmail($order, $config);
}
}