magento以编程方式设置存储id


magento set store id programmatically

我目前正在开发一个有两种语言(法语和荷兰语)的magento网站。我采取的方法如下:

  • 在web根目录中创建一个文件夹(名为nl)
  • 将index.php和.htaccess文件导入该文件夹
  • 在index.php中,我修改了以下行:

    Mage::run('nl'); // to specify the store view i want to load
    

当我检查时,类别、CMS内容等仍然是默认语言。以下代码:

Mage::app()->getStore()->getName();

返回fr商店的名称。

我做错了什么?我认为一个可行的解决方案是将存储设置为在index.php…中运行

有人能告诉我如何通过ID加载商店吗?

经过几个小时的摸索,我找到了一种用程序设置商店id的方法:)

在index.php文件中(在特定语言的文件夹中),添加以下内容:-

$store_id = 'your_store_id_here';
$mageRunCode = 'store view code';
$mageRunType = 'store';
Mage::app()->setCurrentStore($store_id);
Mage::run($mageRunCode, $mageRunType);

希望有人能发现这些信息有用:)

您将在这里获得所有商店的详细信息

<?php
$allStores = Mage::app()->getStores();
foreach ($allStores as $_eachStoreId => $val) 
{
$_storeCode = Mage::app()->getStore($_eachStoreId)->getCode();
$_storeName = Mage::app()->getStore($_eachStoreId)->getName();
$_storeId = Mage::app()->getStore($_eachStoreId)->getId();
echo $_storeId;
echo $_storeCode;
echo $_storeName;
}
?>

要重定向到指定的商店,您需要将页面与商店代码一起重定向。

http://www.mywebsite.com/index.php/store_code/

请查看模板/page/switch/stores.html了解更多详细信息

如果你做htaccess的原因是为了生成特定于每个商店的URL,你可能想使用为你做这件事的配置选项,应该在系统>配置>Web