<?php
namespace CioGuestRedirect\Subscriber;
use CioImports\Event\ImportStockMissingProductNotificationEvent;
use Shopware\Core\Checkout\Cart\Exception\CustomerNotLoggedInException;
use Shopware\Core\Checkout\Customer\Event\CustomerDeletedEvent;
use Shopware\Core\Framework\Event\BusinessEvent;
use Shopware\Core\Framework\Event\BusinessEventCollectorEvent;
use Shopware\Core\Framework\Event\BusinessEventDefinition;
use Shopware\Storefront\Controller\AuthController;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Shopware\Storefront\Event\StorefrontRenderEvent;
class RedirectSubscriber implements EventSubscriberInterface
{
CONST WHITELIST_ROUTES = [
'/account/login',
'/widgets/checkout/info',
'/account/recover',
'/account/recover/password',
'/checkout/offcanvas',
'/cookie/offcanvas',
'/impressum'
];
public static function getSubscribedEvents(): array
{
// Return the events to listen to as array like this: <event to listen to> => <method to execute>
return [
'Shopware\Storefront\Event\StorefrontRenderEvent' => 'onStorefrontRenderEvent'
];
}
public function onStorefrontRenderEvent(StorefrontRenderEvent $event)
{
if($event->getSalesChannelContext()->getSalesChannel()->isMaintenance()) {
return;
}
if (in_array($event->getRequest()->getPathInfo(), self::WHITELIST_ROUTES)) {
return;
}
if ($event->getSalesChannelContext()->getCustomer() === null) {
throw new CustomerNotLoggedInException();
}
}
}