custom/plugins/b2bsellerscore/src/Components/MailTemplate/Subscriber/MailSubscriber.php line 24

Open in your IDE?
  1. <?php
  2. namespace B2bSellersCore\Components\MailTemplate\Subscriber;
  3. use B2bSellersCore\Components\MailTemplate\Events\MailAttachmentInterface;
  4. use Shopware\Core\Content\Flow\Events\FlowSendMailActionEvent;
  5. use Shopware\Core\Content\MailTemplate\Event\MailSendSubscriberBridgeEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class MailSubscriber implements EventSubscriberInterface
  8. {
  9.     public static function getSubscribedEvents(): array
  10.     {
  11.         return [
  12.             FlowSendMailActionEvent::class => 'addAttachments',
  13.             MailSendSubscriberBridgeEvent::class => 'addAttachments'
  14.         ];
  15.     }
  16.     /**
  17.      * @param FlowSendMailActionEvent|MailSendSubscriberBridgeEvent $event
  18.      * @return void
  19.      */
  20.     public function addAttachments($event)
  21.     {
  22.         if ($event instanceof FlowSendMailActionEvent) {
  23.             $mailEvent $event->getFlowEvent()->getEvent();
  24.         } else {
  25.             $mailEvent $event->getBusinessEvent()->getEvent();
  26.         }
  27.         if (!$mailEvent instanceof MailAttachmentInterface) {
  28.             return;
  29.         }
  30.         $attachments = [];
  31.         if ($event->getDataBag()->has('binAttachments')) {
  32.             $attachments $event->getDataBag()->get('binAttachments');
  33.         }
  34.         $attachments array_merge($attachments$mailEvent->getAttachments());
  35.         $event->getDataBag()->set('binAttachments'$attachments);
  36.     }
  37. }