Skip to main content

Q. When does Magento decide which store view to use, and when is the current locale set?

1. Index.php calls Mage::run()
2. It calls app/mage.php :: run()
3. run function has self::$_app->run(…) line of code which ultimatately calls Mage_Core_Model_App::run() function
4. Mage_Core_Model_App::run() includes $this->_initCurrentStore($scopeCode, $scopeType);
5. _initCurrentStore() :: Loads all websites, group and stores into website, group and store object using _initStores() method. this function checks whether the site is website or store group or store, if it is one these then there it sets current store. If scope is base, then it goes through $this->_checkCookieStore()
6. $this->_checkCookieStore() :: this gets the store type from cookie this->getCookie()->get(Mage_Core_Model_Store::COOKIE_NAME);, there it checks whether it is website, group or store and set current store in $this->_currentStore = $store; on the base of value returned by cookie.
7. Mage_Core_Model_App::_checkGetStore() , this checks current store with the xpath_of_store_url , updates cookie

FINALLY, Current locale is set when Mage_Core_Model_App::init() is called , init() function has $this->_initEnvironment(); which has a setting of locale

By Michael Cristancho

I'm a Digital Commerce and Experience evangelist who enjoys engaging in thought-provoking conversation and mutual exploration. I am a strong believer that learning never ends, and each day brings another opportunity to grow as an individual and professional.