custom/plugins/AcrisShopSwitchCS/src/Subscriber/ResponseRedirectSubscriber.php line 23

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Acris\ShopSwitch\Subscriber;
  3. use Acris\ShopSwitch\Components\Struct\RedirectResponseStruct;
  4. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  5. use Shopware\Storefront\Framework\Routing\StorefrontResponse;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  8. use Symfony\Component\HttpKernel\KernelEvents;
  9. class ResponseRedirectSubscriber implements EventSubscriberInterface
  10. {
  11.     public static function getSubscribedEvents()
  12.     {
  13.         return [
  14.             KernelEvents::RESPONSE => [
  15.                 ['setResponseCache'9000]
  16.             ]
  17.         ];
  18.     }
  19.     public function setResponseCache(ResponseEvent $event)
  20.     {
  21.         $response $event->getResponse();
  22.         if($response instanceof StorefrontResponse && $response->getContext() instanceof SalesChannelContext) {
  23.             $salesChannelContext $response->getContext();
  24.             if($salesChannelContext->hasExtension(RedirectResponseStruct::EXTENSION_KEY) === true) {
  25.                 $event->setResponse($salesChannelContext->getExtension(RedirectResponseStruct::EXTENSION_KEY)->getRedirectResponse());
  26.             }
  27.         }
  28.     }
  29. }