php magento 以编程方式设置商店 ID

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9870417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 07:49:43  来源:igfitidea点击:

magento set store id programmatically

phpmagentomagento-1.4

提问by maximus 69

I am currently working on a magento site that is in 2 languages (French and Dutch). The approach I am taking is as follows:

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

  • Create a folder in the web root (named nl)
  • Import the index.php and .htaccess file to that folder
  • In the index.php I modify the following line:

    Mage::run('nl'); // to specify the store view i want to load
    
  • 在 Web 根目录中创建一个文件夹(名为 nl)
  • 将 index.php 和 .htaccess 文件导入该文件夹
  • 在 index.php 中,我修改了以下行:

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

When I check, the categories, CMS content etc are still in the default language. The following code:

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

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

returns the fr store's name.

返回 fr 商店的名称。

What is it that I'm doing wrong? I think a viable solution would be to set the store to run in index.php...

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

Could someone please let me know how to load a store by ID?

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

回答by maximus 69

After hours of huffing and puffing i was able to figure out a way to set the store id programatically :)

经过数小时的喘气和喘气,我找到了一种以编程方式设置商店 ID 的方法:)

In the index.php file, (in your language specific folder), add the following:-

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

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

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

Hope someone will find this information useful :)

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

回答by Sarath Tomy

You will get all store details here

您将在此处获得所有商店详细信息

<?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;
}
?>

To redirect to the specified store, you need to redirect the page along with the store code.

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

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

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

Please check the template/page/switch/stores.phtml for more details

请查看模板/页面/switch/stores.phtml 了解更多详情

回答by kalenjordan

If the reason you're doing the htaccess stuff is so that you can generate URLs specific to each store, you may want to go with the configuration option that does that for you, should be in System > Config > Web

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