I want to get the default store id of currently active website. I tried

Mage::app()->getStoreId()

It gets the current store but not the default store id of the current website.
How can I get it ? Any suggestions will be appreciated.

有帮助吗?

解决方案

Assuming you're talking about the default store id defined per store group, then e.g. like this:

$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 true to the method getWebsite() :

$iDefaultStoreId = Mage::app()
    ->getWebsite(true)
    ->getDefaultGroup()
    ->getDefaultStoreId();

其他提示

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.

$iDefaultStoreId = Mage::app()
    ->getWebsite($websiteId)
    ->getDefaultGroup()
    ->getDefaultStoreId();

Hope this helps some Googlers.

you can get default store id like following:

Mage_Core_Model_App::ADMIN_STORE_ID
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top