Magento 2:“未找到请求的商店。请验证商店,然后重试。

Magento 2: “The store that was requested wasn't found. Verify the store and try again.”

提问人:KaMZaTa 提问时间:4/1/2020 最后编辑:Gerard de VisserKaMZaTa 更新时间:3/28/2022 访问量:19138

问:

每次我从英语商店视图切换到意大利语商店视图时,反之亦然,它都会将我带到等效的主页(无论我在哪里),并抛出此错误:

The store that was requested wasn't found. Verify the store and try again.

这是我的设置:

  • Magento 2.3.4(全新安装,自托管)
  • 1 个网站、1 家商店、2 个商店浏览量
  • 对于每个商店,查看一个不同的域(英语商店视图 --> example.com,意大利语商店视图 --> example.it)
  • 我在主要的.htaccess之上添加了这些环境:

    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

有什么想法吗?


我测试了什么:

  • 我尝试在第 106 行的 /vendor/magento/module-store/Controller/Store/SwitchAction.php 中对存储视图代码进行硬编码,$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);
    }
    ...
    

    下面是一个开关 url 示例:https://example.com/stores/store/redirect/___store/it/___from_store/en/uenc/aHR0cHM6Ly9kZXYudGVjbmljbWFuLml0Lz9fX19zdG9yZT1pdA%2C%2C/

然后我从意大利商店视图切换到英语商店视图,它奏效了!因此,它似乎无法获得正确的$targetStoreCode值,并$requestedUrlToRedirect。有什么想法吗?

php magento magento2

评论


答:

3赞 KaMZaTa 4/17/2020 #1

这是一个Magento 2.3.1到2.3.5的错误。问题出在眼前......正好在 module-store/view/frontend/templates/switch/languages.phtml 的第 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>

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

0赞 Robert Łoziński 7/17/2020 #2

请尝试清除表“flag”中的所有数据。

0赞 Kalif Mihai 8/24/2020 #3

确保数据库中的表名称中没有soft_。我不得不修改所有表格以匹配描述: 将 alter table 重命名soft_adminnotification_inbox重命名为 adminnotification_inbox .. .. ..

0赞 Gerard de Visser 3/28/2022 #4

问题还可能是数据库表core_config_data包含不再存在的存储视图的记录。

在这种情况下,手动删除此记录将解决该错误。