Magento 2:“找不到请求的商店。验证商店并重试。”

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

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

这是我的设置:

回顾: 例如,如果我在 example.com/my-beautiful-product.html [ 英语商店视图],我正在切换到意大利商店视图,它带我到 example.it 并显示错误 ( "The store that was requested wasn't found. Verify the store and try again.") 而不是带我去 示例。it/my-beautiful-product.html 没有任何错误。

有什么想法吗?


我测试的内容:

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

这是一个 Magento 2.3.1 到 2.3.5 的错误。问题出在视图中...并且恰好在第 28 行的 module-store/view/frontend/templates/switch/languages.phtml 中。

错误

<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>

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

请尝试清除 table“标志”中的所有数据。

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

问题也可能是数据库 table core_config_data 包含(不再)存在的商店视图的记录。

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