4

I've found the following line of code used in some of our one-off scripts, and have also found it used in various unofficial (i.e. not entirely trustworthy) websites:

Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);

In our usage it's called during the bootstrapping of various .php scripts; things like one-time data-load scripts.

In debugging I see that it change's the current store's Id to zero; however I don't understand the reason or need to do so.

What purpose would this serve, and when (if at all) would it be correct to be used?

4

There are some methods that require an admin level to perform properly as they will be applied across all store views.

By default the store ID will always be set as 1 if not specified, causing some methods to fail or odd behaviour.

An example would be needing to apply a scripted change across all store views, for example product Images or such.

  • Thanks for the info--so it effectively pretends that the current store is the global (all stores) store? – STW Jul 16 '14 at 18:59
  • Not necessarily "pretends" but if you poke around enough Core/Mage Models theres most always some conditions or arguments involving the store views. Example: svn.magentocommerce.com/source/branches/1.9/app/code/core/Mage/… – B00MER Jul 17 '14 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.