Magento 2:“未找到所请求的商店.验证商店,然后重试." [英] Magento 2: “The store that was requested wasn't found. Verify the store and try again.”

查看:464
本文介绍了Magento 2:“未找到所请求的商店.验证商店,然后重试."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我从英语商店视图切换到意大利商店视图时,反之亦然,这将我带到等效的主页(无论我身在何处),并且会引发此错误:

Everytime I'm switching from the English store view to the Italian's one and viceversa, it takes me to the equivalent homepage (no matters where I am) and it throws this error:

这是我的设置:

  • Magento 2.3.4(全新安装,自行托管)
  • 1个网站,1个商店,2个商店访问量
  • 对于每个商店视图,一个不同的域(英语商店视图-> example.com,意大利商店视图-> example.it)
  • 我在主要.htaccess文件的顶部添加了这些env:

  • Magento 2.3.4 (fresh installation, self hosted)
  • 1 website, 1 store, 2 store views
  • For each store view one different domain (English store view --> example.com, Italian store view --> example.it)
  • I added on top of main .htaccess these env:

SetEnvIf Host ^(.*)\.example\.com MAGE_RUN_CODE=en
SetEnvIf Host ^(.*)\.example\.com MAGE_RUN_TYPE=store
SetEnvIf Host ^(.*)\.example\.it MAGE_RUN_CODE=it
SetEnvIf Host ^(.*)\.example\.it MAGE_RUN_TYPE=store

回顾:例如,如果我在 example.com/my-beautiful-product.html 上,[英语商店视图 ],然后切换到意大利语商店视图,将我带到 example.it ,并显示该错误(未找到所请求的商店.请验证商店,然后重试. "),而不是将我带到 example.it/my-beautiful-product.html 上,没有任何错误.

Recap: If, for example, I'm on example.com/my-beautiful-product.html [English store view] and I'm switching to the Italian store view, it takes me to example.it and it shows that error ("The store that was requested wasn't found. Verify the store and try again.") instead of take me on example.it/my-beautiful-product.html without any errors.

有什么想法吗?

  • 我试图在第106行的/vendor/magento/module-store/Controller/Store/SwitchAction.php 和$ requestedUrlToRedirect中对商店视图代码进行硬编码:

  • I tried to hardcode the store view codes in /vendor/magento/module-store/Controller/Store/SwitchAction.php at row 106 and the $requestedUrlToRedirect :

...
public function execute()
{
    $targetStoreCode = $this->_request->getParam(
        \Magento\Store\Model\StoreManagerInterface::PARAM_NAME
    );
    $fromStoreCode = $this->_request->getParam(
        '___from_store',
        $this->storeCookieManager->getStoreCodeFromCookie()
    );

    $requestedUrlToRedirect = 'https://example.it/my-beautiful-product.html';
    $redirectUrl = $requestedUrlToRedirect;
    // $requestedUrlToRedirect = $this->_redirect->getRedirectUrl();
    // $redirectUrl = $requestedUrlToRedirect;

    $error = null;
    try {
        $fromStore = $this->storeRepository->get('en');
        $targetStore = $this->storeRepository->getActiveStoreByCode('it');
        // $fromStore = $this->storeRepository->get($fromStoreCode);
        // $targetStore = $this->storeRepository->getActiveStoreByCode($targetStoreCode);
    } catch (StoreIsInactiveException $e) {
        $error = __('Requested store is inactive');
    } catch (NoSuchEntityException $e) {
        $error = __("The store that was requested wasn't found. Verify the store and try again.");
    }
    if ($error !== null) {
        $this->messageManager->addErrorMessage($error);
    } else {
        $redirectUrl = $this->storeSwitcher->switch($fromStore, $targetStore, $requestedUrlToRedirect);
    }

    $this->getResponse()->setRedirect($redirectUrl);
}
...

这里有一个切换网址示例: https://example.com/stores/store/redirect/___store/it/___from_store/zh-CN/uenc/aHR0cHM6Ly9kZXYudGVjbmljbWFuLml0Lz9fX19zdG9yZT1pdA%2C%2C/

Here a switch url example: https://example.com/stores/store/redirect/___store/it/___from_store/en/uenc/aHR0cHM6Ly9kZXYudGVjbmljbWFuLml0Lz9fX19zdG9yZT1pdA%2C%2C/

然后,我从意大利语商店视图切换到英语商店视图,并且起作用了!!因此,似乎无法获取$ targetStoreCode和$ requestedUrlToRedirect的正确值 >.有什么想法吗?

Then I switched from Italian store view to the English one and it worked! So it seems it does not able to get the correct values of $targetStoreCode, and $requestedUrlToRedirect. Any ideas?

推荐答案

这是Magento 2.3.1至2.3.5的错误.问题出在视图中……确切地在第28行的module-store/view/frontend/templates/switch/languages.phtml中.

It's a Magento 2.3.1 to 2.3.5 bug. The problem is in the view... and exactly in module-store/view/frontend/templates/switch/languages.phtml at the line 28.

错误

<li class="view-<?= $block->escapeHtml($_lang->getCode()) ?> switcher-option">
    <a href="<?= $block->escapeUrl($block->getViewModel()->getTargetStoreRedirectUrl($_lang)) ?>">
        <?= $block->escapeHtml($_lang->getName()) ?>
    </a>
</li>

正确

<li class="view-<?= $block->escapeHtml($_lang->getCode()) ?> switcher-option">
    <a href="#" data-post='<?= /* @noEscape */ $block->getTargetStorePostData($_lang) ?>'>
        <?= $block->escapeHtml($_lang->getName()) ?>
    </a>
</li>

...现在它就像一种魅力!

...and now it works like a charm!

这篇关于Magento 2:“未找到所请求的商店.验证商店,然后重试."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆