<?php declare(strict_types=1);
namespace Samson\Subscriber;
/***
*
* This file is part of the "SAMSON Shop" project.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2022
*
***/
use Shopware\Core\Content\Newsletter\Event\NewsletterRegisterEvent;
use Shopware\Storefront\Controller\StorefrontController;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Class NewsletterSubscriber
* @package Samson\Subscriber
* @author Christian Schmitz <christian.schmitz@dkd.de>
*/
class NewsletterSubscriber implements EventSubscriberInterface
{
private Session $session;
private TranslatorInterface $translator;
public function __construct(Session $session,
TranslatorInterface $translator
)
{
$this->session = $session;
$this->translator = $translator;
}
public static function getSubscribedEvents(): array
{
return [
NewsletterRegisterEvent::class => 'onNewsletterRegisterEvent'
];
}
public function onNewsletterRegisterEvent(NewsletterRegisterEvent $event): void
{
$email = $event->getNewsletterRecipient()->getEmail();
$message = $this->translator->trans('account.customerNewsletterRegistration', ['%email%' => $email]);
$this->session->getFlashBag()->add(StorefrontController::INFO, $message);
}
}