magento以编程方式设置商店ID

时间:2012-03-26 10:22:41

标签: php magento magento-1.4

我目前正在使用2种语言(法语和荷兰语)的magento网站。我采取的方法如下:

  • 在网络根目录中创建一个文件夹(名为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加载商店吗?

3 个答案:

答案 0 :(得分:27)

经过几个小时的喘息和喘气,我能够找到一种以编程方式设置商店ID的方法:)

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

$store_id = 'your_store_id_here';
$mageRunCode = 'store view code';
$mageRunType = 'store';

Mage::app()->setCurrentStore($store_id);
Mage::run($mageRunCode, $mageRunType);

希望有人会发现此信息有用:)

答案 1 :(得分:5)

您将在此处获取所有商店详情

<?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.phtml了解更多详情

答案 2 :(得分:3)

如果您正在执行htaccess操作的原因是您可以生成特定于每个商店的URL,您可能希望使用为您执行此操作的配置选项,应该在System&gt;中。配置&gt;网络

相关问题