Esempio n. 1
0
    /**
     * @return void
     */
    public function executeInternal()
    {
        $storeCode = $this->_request->getParam(
            StoreResolver::PARAM_NAME,
            $this->storeCookieManager->getStoreCodeFromCookie()
        );

        try {
            $store = $this->storeRepository->getActiveStoreByCode($storeCode);
        } catch (StoreIsInactiveException $e) {
            $error = __('Requested store is inactive');
        } catch (NoSuchEntityException $e) {
            $error = __('Requested store is not found');
        }

        if (isset($error)) {
            $this->messageManager->addError($error);
            $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
            return;
        }

        $defaultStoreView = $this->storeManager->getDefaultStoreView();
        if ($defaultStoreView->getId() == $store->getId()) {
            $this->storeCookieManager->deleteStoreCookie($store);
        } else {
            $this->httpContext->setValue(Store::ENTITY, $store->getCode(), $defaultStoreView->getCode());
            $this->storeCookieManager->setStoreCookie($store);
        }

        $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
    }
Esempio n. 2
0
 /**
  * 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());
         }
     }
 }
 /**
  * Retrieve active store by code
  *
  * @param string $storeCode
  * @return \Magento\Store\Api\Data\StoreInterface
  * @throws NoSuchEntityException
  */
 protected function getRequestedStoreByCode($storeCode)
 {
     try {
         $store = $this->storeRepository->getActiveStoreByCode($storeCode);
     } catch (StoreIsInactiveException $e) {
         throw new NoSuchEntityException(__('Requested store is inactive'));
     }
     return $store;
 }