Magento 2:“找不到请求的商店。验证商店并重试。”
Magento 2: “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)
我在 main .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 并显示错误 ( "The store that was requested wasn't found. Verify the store and try again.") 而不是带我去 示例。it/my-beautiful-product.html 没有任何错误。
有什么想法吗?
我测试的内容:
我试图在 /vendor/magento/module-store/Controller/Store/SwitchAction.php 中的第 106 行和 $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);
}
...
然后我从意大利商店视图切换到英语商店视图,成功了!所以它似乎无法获得 $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 包含(不再)存在的商店视图的记录。
在这种情况下,手动删除此记录将解决错误。
每次我从英文商店视图切换到意大利语商店视图,反之亦然,它会将我带到等效的主页(无论我在哪里)并抛出此错误:
这是我的设置:
- Magento 2.3.4(全新安装,自托管)
- 1 个网站,1 个商店,2 次商店浏览量
- 对于每个商店视图一个不同的域(英语商店视图 --> example.com,意大利语商店视图 --> example.it)
我在 main .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 并显示错误 ( "The store that was requested wasn't found. Verify the store and try again.") 而不是带我去 示例。it/my-beautiful-product.html 没有任何错误。
有什么想法吗?
我测试的内容:
我试图在 /vendor/magento/module-store/Controller/Store/SwitchAction.php 中的第 106 行和 $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); } ...
然后我从意大利商店视图切换到英语商店视图,成功了!所以它似乎无法获得 $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 包含(不再)存在的商店视图的记录。
在这种情况下,手动删除此记录将解决错误。