<?php
declare(strict_types=1);
namespace Nextag\Mail\Subscriber;
use Psr\Log\LoggerInterface;
use Shopware\Core\Checkout\Document\DocumentService;
use Shopware\Core\Content\Mail\Service\AbstractMailService;
use Shopware\Core\Content\MailTemplate\Exception\MailEventConfigurationException;
use Shopware\Core\Content\MailTemplate\Exception\SalesChannelNotFoundException;
use Shopware\Core\Content\MailTemplate\MailTemplateActions;
use Shopware\Core\Content\Media\MediaService;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\EventDispatcher\Event;
class MailSendSubscriber implements EventSubscriberInterface
{
public const ACTION_NAME = MailTemplateActions::MAIL_TEMPLATE_MAIL_SEND_ACTION;
public const MAIL_CONFIG_EXTENSION = 'mail-attachments';
public function __construct(
AbstractMailService $emailService,
EntityRepositoryInterface $mailTemplateRepository,
MediaService $mediaService,
EntityRepositoryInterface $mediaRepository,
EntityRepositoryInterface $documentRepository,
DocumentService $documentService,
LoggerInterface $logger,
EventDispatcherInterface $eventDispatcher
) {
$this->mailTemplateRepository = $mailTemplateRepository;
$this->mediaService = $mediaService;
$this->mediaRepository = $mediaRepository;
$this->documentRepository = $documentRepository;
$this->documentService = $documentService;
$this->logger = $logger;
$this->emailService = $emailService;
$this->eventDispatcher = $eventDispatcher;
}
public static function getSubscribedEvents(): array
{
return [
self::ACTION_NAME => 'sendMail',
];
}
/**
* @throws MailEventConfigurationException
* @throws SalesChannelNotFoundException
* @throws InconsistentCriteriaIdsException
*/
public function sendMail(Event $event): void
{
$mailEvent = $event->getEvent();
if ($mailEvent instanceof \Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent) {
$event->stopPropagation();
}
}
}