custom/plugins/NetiNextEasyCoupon/src/Subscriber/Mail.php line 46

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * @copyright Copyright (c) 2020, Net Inventors GmbH
  5.  * @category  Shopware
  6.  * @author    mpeters
  7.  */
  8. namespace NetInventors\NetiNextEasyCoupon\Subscriber;
  9. use NetInventors\NetiNextEasyCoupon\Service\OrderVoucherService;
  10. use NetInventors\NetiNextEasyCoupon\Service\PluginConfig;
  11. use Shopware\Core\Checkout\Order\OrderEntity;
  12. use Shopware\Core\Content\MailTemplate\Service\Event\MailBeforeValidateEvent;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. class Mail implements EventSubscriberInterface
  15. {
  16.     /**
  17.      * @var PluginConfig
  18.      */
  19.     private $config;
  20.     /**
  21.      * @var OrderVoucherService
  22.      */
  23.     private $orderVoucherService;
  24.     public function __construct(PluginConfig $configOrderVoucherService $orderVoucherService)
  25.     {
  26.         $this->config              $config;
  27.         $this->orderVoucherService $orderVoucherService;
  28.     }
  29.     /**
  30.      * @return string[]
  31.      */
  32.     public static function getSubscribedEvents(): array
  33.     {
  34.         return [
  35.             MailBeforeValidateEvent::class => 'beforeMailValidate',
  36.         ];
  37.     }
  38.     public function beforeMailValidate(MailBeforeValidateEvent $event): void
  39.     {
  40.         if (!(
  41.             $this->config->isActive()
  42.             && isset($event->getTemplateData()['order'])
  43.             && $event->getTemplateData()['order'] instanceof OrderEntity
  44.         )) {
  45.             return;
  46.         }
  47.         $this->orderVoucherService->addPurchaseVouchersToOrder($event->getTemplateData()['order'], $event->getContext());
  48.     }
  49. }