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

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