<?php declare(strict_types=1);
namespace Shopware\Storefront\Event;
use Shopware\Core\Checkout\Cart\Event\CartMergedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Contracts\Translation\TranslatorInterface;
class CartMergedSubscriber implements EventSubscriberInterface
{
/**
* @var Session
*/
private $session;
/**
* @var TranslatorInterface
*/
private $translator;
public function __construct(
Session $session,
TranslatorInterface $translator
) {
$this->session = $session;
$this->translator = $translator;
}
public static function getSubscribedEvents(): array
{
return [
CartMergedEvent::class => 'addCartMergedNoticeFlash',
];
}
public function addCartMergedNoticeFlash(CartMergedEvent $event): void
{
$this->session->getFlashBag()->add('info', $this->translator->trans('checkout.cart-merged-hint'));
}
}