Magento: Retrieve the store name, inside a module

Mar 17, 2011

I thought this would be simple usually that is my first mistake with Magento. As it transpires it really is simple for once but worth mentioning, if only so that when I need it again in six months time I have it written down somewhere.

There are plenty of reasons you might want to do this, from turning functionality on or off within your module – or like in my case – using the store code as a prefix on order numbers.

The following PHP should be fairly self explanatory.

$magento_store = Mage::app()->getStore();
$store_name = $magento_store->getName();