custom/plugins/AcrisShopSwitchCS/src/Subscriber/LanguageSwitchRequestSubscriber.php line 22

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Acris\ShopSwitch\Subscriber;
  3. use Acris\ShopSwitch\Components\ShopSwitchRedirectService;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\Event\RequestEvent;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. class LanguageSwitchRequestSubscriber implements EventSubscriberInterface
  8. {
  9.     public static function getSubscribedEvents()
  10.     {
  11.         return [
  12.             KernelEvents::REQUEST => [
  13.                 ['onKernelRequestAddShopSwitchDone']
  14.             ]
  15.         ];
  16.     }
  17.     public function onKernelRequestAddShopSwitchDone(RequestEvent $event)
  18.     {
  19.         if(!empty($event->getRequest()) && $event->getRequest()->attributes->has('_route') && $event->getRequest()->attributes->get('_route') === 'frontend.checkout.switch-language') {
  20.             $redirectParameters = [];
  21.             if(!empty($event->getRequest()->get('redirectParameters')) && is_array($event->getRequest()->get('redirectParameters'))) {
  22.                 $redirectParameters $event->getRequest()->get('redirectParameters');
  23.             }
  24.             $redirectParameters[ShopSwitchRedirectService::SWITCH_DONE_PARAM_NAME] = 1;
  25.             $event->getRequest()->request->set('redirectParameters'$redirectParameters);
  26.         }
  27.     }
  28. }