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

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