magento以编程方式设置商店ID

max*_* 69 10 php magento magento-1.4

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

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

    Mage::run('nl'); // to specify the store view i want to load
    
    Run Code Online (Sandbox Code Playgroud)

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

Mage::app()->getStore()->getName();
Run Code Online (Sandbox Code Playgroud)

返回fr商店的名称.

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

有人可以让我知道如何通过ID加载商店吗?

max*_* 69 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);
Run Code Online (Sandbox Code Playgroud)

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

  • 你也可以选择`$ store = Mage :: getModel('core/store') - > load([store id]);`如果你不想将整个商店全局设置为一件事应用程序.如果您使用相同代码中的客户和产品等几个模型,并且您不希望将结果限制为一个商店,那么这很方便. (3认同)

Sar*_*omy 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;
}
?>
Run Code Online (Sandbox Code Playgroud)

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

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

请查看template/page/switch/stores.phtml以获取更多详细信息