Echo the website, store IDs and store names in Magento

Submitted by deeperdata - 1 year ago

The first method will return the current website, store ID and store name. while the second will return all. Throw into a workbench script to run in isolation: https://gist.github.com/benmarks/4532434

// To output current website, store ID and store name

<?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/>";
?>

// To output all websites, store IDs and store names

foreach (Mage::app()->getWebsites() as $website) {
    foreach ($website->getGroups() as $group) {
        $stores = $group->getStores();
        foreach ($stores as $store) {
            echo $store->getId() ." ".$store->getName()."<br/>";
        }
    }
}
affiliate_link
Learn PHP
comments powered by Disqus
Proudly hosted on Digital Ocean