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

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