Magento 1.9 – How to Get Store ID from Code

magento-1.9store-idstores

So I have the store code and I would really like simply the store id. Ideally I do not want to simply load the store completely as I only need the id.

One idea I had was to load this via a collection but I was wondering if there was another way via a helper or resource.

Best Answer

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
Related Topic