How to get the store id from the code

Mage::getModel('core/store')->load($storeCode, 'code')->getId()

Isn't this the simplest way to do?


Haven't tested this but I seem to remember you can get the ID by using the method loadConfig in the model Mage_Core_Model_Store

After that you can get the ID by calling getId() on the model.

The loadConfig method uses the loaded configuration to retrieve store data

$store = Mage::getConfig()->getNode()->stores->{$code};

Which gives you the following values

  • id
  • code
  • website_id

I don't know if this is something that's peculiar to 1.9.0.0 but I couldn't get either Mage::getConfig()->getNode()->stores->{$code} or Mage::getModel('core/store')->loadConfig($code) (which in fact calls Mage::getConfig()->getNode()->stores->{$code}) to return anything.

The first was close... with a subtle change in form, this gets a result, though it's waaay more info than you need:

$store = Mage::getConfig()->getNode('stores')->{$code}

What worked for me, to get just the store id, was this:

$storeId = Mage::getConfig()->getNode('stores')->{$code}->system->store->id;

...still inefficient, of course, loading all that config info just for one little number. But hey, that's Magento for you.