Getting the website and store IDs and their names in Magento

The below code snippet will output the current website id, website name, store id, store name, and store code in Magento.

echo "Website ID: " . Mage::app()->getWebsite()->getId() . "<br/>"; 
echo "Website Name: " . Mage::app()->getWebsite()->getName() . "<br/>"; 
echo "Store ID: " . Mage::app()->getStore()->getId() . "<br/>"; 
echo "Store Name: ".Mage::app()->getStore()->getName(). "<br/>";
echo "Store code: ". Mage::app()->getStore()->getCode()."<br/>";

The below code snippet will print all the store IDs and store names in Magento.

foreach (Mage::app()->getWebsites() as $website) {
    foreach ($website->getGroups() as $group) {
        $stores = $group->getStores();
        foreach ($stores as $store) {
            echo $store->getId() ." ".$store->getName()."<br/>";

Search within Codexpedia

Custom Search

Search the entire web

Custom Search