custom/static-plugins/SamsonCustomer/src/Subscriber/NewsletterSubscriber.php line 47

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Samson\Subscriber;
  3. /***
  4.  *
  5.  * This file is part of the "SAMSON Shop" project.
  6.  *
  7.  * For the full copyright and license information, please read the
  8.  * LICENSE.txt file that was distributed with this source code.
  9.  *
  10.  *  (c) 2022
  11.  *
  12.  ***/
  13. use Shopware\Core\Content\Newsletter\Event\NewsletterRegisterEvent;
  14. use Shopware\Storefront\Controller\StorefrontController;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. use Symfony\Component\HttpFoundation\Session\Session;
  17. use Symfony\Contracts\Translation\TranslatorInterface;
  18. /**
  19.  * Class NewsletterSubscriber
  20.  * @package Samson\Subscriber
  21.  * @author Christian Schmitz <christian.schmitz@dkd.de>
  22.  */
  23. class NewsletterSubscriber implements EventSubscriberInterface
  24. {
  25.     private Session $session;
  26.     private TranslatorInterface $translator;
  27.     public function __construct(Session             $session,
  28.                                 TranslatorInterface $translator
  29.     )
  30.     {
  31.         $this->session $session;
  32.         $this->translator $translator;
  33.     }
  34.     public static function getSubscribedEvents(): array
  35.     {
  36.         return [
  37.             NewsletterRegisterEvent::class => 'onNewsletterRegisterEvent'
  38.         ];
  39.     }
  40.     public function onNewsletterRegisterEvent(NewsletterRegisterEvent $event): void
  41.     {
  42.         $email $event->getNewsletterRecipient()->getEmail();
  43.         $message $this->translator->trans('account.customerNewsletterRegistration', ['%email%' => $email]);
  44.         $this->session->getFlashBag()->add(StorefrontController::INFO$message);
  45.     }
  46. }