Question

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.

Was it helpful?

Solution

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();

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top