phpmagentomagento-1.6

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


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?


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