vendor/shopware/platform/src/Storefront/Event/CartMergedSubscriber.php line 31

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.     public function __construct(
  12.         TranslatorInterface $translator,
  13.         RequestStack $requestStack
  14.     ) {
  15.         $this->translator $translator;
  16.         $this->requestStack $requestStack;
  17.     }
  18.     public static function getSubscribedEvents(): array
  19.     {
  20.         return [
  21.             CartMergedEvent::class => 'addCartMergedNoticeFlash',
  22.         ];
  23.     }
  24.     public function addCartMergedNoticeFlash(CartMergedEvent $event): void
  25.     {
  26.         /*
  27.         * @feature-depretacted tag:6.5.0.0 (flag:FEATURE_NEXT_16824) - Remove this check on 6.5.0.0
  28.         */
  29.         if ($event->getPreviousCart() === null) {
  30.             return;
  31.         }
  32.         $mainRequest $this->requestStack->getMainRequest();
  33.         if ($mainRequest === null) {
  34.             return;
  35.         }
  36.         if ($mainRequest->hasSession() === false) {
  37.             return;
  38.         }
  39.         $session $mainRequest->getSession();
  40.         if (!method_exists($session'getFlashBag')) {
  41.             return;
  42.         }
  43.         $session->getFlashBag()->add('info'$this->translator->trans('checkout.cart-merged-hint'));
  44.     }
  45. }