<?php declare(strict_types=1);
namespace Acris\ShopSwitch\Subscriber;
use Acris\ShopSwitch\Components\ShopSwitchRedirectService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class LanguageSwitchRequestSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => [
['onKernelRequestAddShopSwitchDone']
]
];
}
public function onKernelRequestAddShopSwitchDone(RequestEvent $event)
{
if(!empty($event->getRequest()) && $event->getRequest()->attributes->has('_route') && $event->getRequest()->attributes->get('_route') === 'frontend.checkout.switch-language') {
$redirectParameters = [];
if(!empty($event->getRequest()->get('redirectParameters')) && is_array($event->getRequest()->get('redirectParameters'))) {
$redirectParameters = $event->getRequest()->get('redirectParameters');
}
$redirectParameters[ShopSwitchRedirectService::SWITCH_DONE_PARAM_NAME] = 1;
$event->getRequest()->request->set('redirectParameters', $redirectParameters);
}
}
}