vendor/shopware/storefront/Event/CartMergedSubscriber.php line 33

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Event;
  3. use Shopware\Core\Checkout\Cart\Event\CartMergedEvent;
  4. use Shopware\Core\Framework\Log\Package;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use Symfony\Contracts\Translation\TranslatorInterface;
  8. /**
  9.  * @internal
  10.  */
  11. #[Package('storefront')]
  12. class CartMergedSubscriber implements EventSubscriberInterface
  13. {
  14.     /**
  15.      * @internal
  16.      */
  17.     public function __construct(
  18.         private readonly TranslatorInterface $translator,
  19.         private readonly RequestStack $requestStack
  20.     ) {
  21.     }
  22.     public static function getSubscribedEvents(): array
  23.     {
  24.         return [
  25.             CartMergedEvent::class => 'addCartMergedNoticeFlash',
  26.         ];
  27.     }
  28.     public function addCartMergedNoticeFlash(CartMergedEvent $event): void
  29.     {
  30.         $mainRequest $this->requestStack->getMainRequest();
  31.         if ($mainRequest === null) {
  32.             return;
  33.         }
  34.         if ($mainRequest->hasSession() === false) {
  35.             return;
  36.         }
  37.         $session $mainRequest->getSession();
  38.         if (!method_exists($session'getFlashBag')) {
  39.             return;
  40.         }
  41.         $session->getFlashBag()->add('info'$this->translator->trans('checkout.cart-merged-hint'));
  42.     }
  43. }