Get default store id of website in Magento

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