How do I get the default store ID of a website in Magento?

24,617

Solution 1

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

Solution 2

you can get default store id like following:

Mage_Core_Model_App::ADMIN_STORE_ID
Share:
24,617
user773440
Author by

user773440

Updated on December 22, 2021

Comments

  • user773440
    user773440 over 2 years

    I want to get the default store ID of currently active website. I tried Mage::app()->getStoreId(), but that gets the current store, not the default store ID of the current website.

    How can I get it?

  • Tahir Yasin
    Tahir Yasin over 10 years
    This doesn't work in Magento admin scope but works on front-end.