storeManager = $storeManager; $this->storeCookieManager = $storeCookieManager; $this->storeRepository = $storeRepository; } /** * Delete cookie "store" if the store (a value in the cookie) does not exist or is inactive * * @param \Magento\Framework\App\FrontController $subject * @param \Magento\Framework\App\RequestInterface $request * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeDispatch( \Magento\Framework\App\FrontController $subject, \Magento\Framework\App\RequestInterface $request ) { $storeCodeFromCookie = $this->storeCookieManager->getStoreCodeFromCookie(); if ($storeCodeFromCookie) { try { $this->storeRepository->getActiveStoreByCode($storeCodeFromCookie); } catch (StoreIsInactiveException $e) { $this->storeCookieManager->deleteStoreCookie($this->storeManager->getDefaultStoreView()); } catch (NoSuchEntityException $e) { $this->storeCookieManager->deleteStoreCookie($this->storeManager->getDefaultStoreView()); } catch (InvalidArgumentException $e) { $this->storeCookieManager->deleteStoreCookie($this->storeManager->getDefaultStoreView()); } } } }