php 在 Magento 中获取网站的默认商店 ID
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11243574/
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
Get default store id of website in Magento
提问by user773440
I want to get the default store id of currently active website. I tried
我想获取当前活动网站的默认商店 ID。我试过
Mage::app()->getStoreId()
Mage::app()->getStoreId()
我怎么才能得到它 ?任何建议将不胜感激。
回答by Jürgen Thelen
Assuming you're talking about the default store id defined per store group, then e.g. like this:
假设您正在谈论为每个商店组定义的默认商店 ID,那么例如像这样:
$iDefaultStoreId = Mage::app()
->getWebsite()
->getDefaultGroup()
->getDefaultStoreId();
The original question was on how to retrieve the default store ID of currently active website, so the answer is correct. However in order to get the default frontend store ID from within the admin panel you need to pass the parameter trueto the method getWebsite():
最初的问题是如何检索当前活动网站的默认商店ID,所以答案是正确的。但是,为了从管理面板中获取默认的前端商店 ID,您需要将参数传递true给方法getWebsite():
$iDefaultStoreId = Mage::app()
->getWebsite(true)
->getDefaultGroup()
->getDefaultStoreId();
回答by Shadoweb
To answer to the comment of @Tahir Yasin that it doesn't work on Admin, it's because the Admin default website_id is 0, so is the store_id, so not really useful there. What you need for Admin is specify the website ID.
要回答@Tahir Yasin 的评论,它在 Admin 上不起作用,这是因为 Admin 默认 website_id 为 0,store_id 也是如此,所以在那里并没有真正有用。您需要为 Admin 指定网站 ID。
$iDefaultStoreId = Mage::app()
->getWebsite($websiteId)
->getDefaultGroup()
->getDefaultStoreId();
Hope this helps some Googlers.
希望这对一些 Google 员工有所帮助。
回答by Hassan Ali Shahzad
you can get default store id like following:
您可以获得如下所示的默认商店 ID:
Mage_Core_Model_App::ADMIN_STORE_ID

