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.
[code language=”php”]
<?php
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/>";
?>
[/code]
The below code snippet will print all the store IDs and store names in Magento.
[code language=”php”]
foreach (Mage::app()->getWebsites() as $website) {
foreach ($website->getGroups() as $group) {
$stores = $group->getStores();
foreach ($stores as $store) {
echo $store->getId() ." ".$store->getName()."<br/>";
}
}
}
[/code]
Search within Codexpedia

Search the entire web
