Magento Certified Developer GuideCategory: 2. Request FlowWhen does Magento decide which store view to use, and when is the current locale set
Manish Prakash Staff asked 5 years ago

Store View Initialization

This happens in ‘core/app’ model in the _initCurrentStore() function. What this function does is, reads all stores information database. This is information is read from ‘core/website’ , ‘core/store’ , ‘core/store_group’ and it iterates over these objects and assigns them accordingly. It also check which is the default website and stores that in a separate variable $this->_website

From index.php we call the Mage::run() we pass two parameters ($storeScope and $storeType), both these parameters are used here.
$scopeType: can be website, store, group (if empty its treated as website)
$storeScope: this is code of (website or store etc according to type)

based of this the default website, store etc is initialized.

Next we also have two functions

            $this->_checkCookieStore($scopeType);
            $this->_checkGetStore($scopeType);

Both these function check cookie and $_GET[‘___store’] if there is a store code present in them. If it’s present that store code is regarded as the current store.

Locale Initialization
This happens in the _initEnvironment() at line Mage_Core_Model_Locale::DEFAULT_TIMEZONE
When the class ‘core/locale’ is initialized, the constructor get called which automatically read locale from system configuration and initializes it.