Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different locale Settings don't work #479

Closed
sepple opened this issue Jan 22, 2014 · 8 comments
Closed

Different locale Settings don't work #479

sepple opened this issue Jan 22, 2014 · 8 comments

Comments

@sepple
Copy link

sepple commented Jan 22, 2014

I was creating two store views and configured different locale settings in the backend. A store switch does not change the locale. Seems like just the default locale is used.

@verklov
Copy link
Contributor

verklov commented Jan 22, 2014

@sepple , could you please provide more details? I have just created two store views and set English for one and German for the other. On the frontend the locale were switched once I switched store views.

@sepple
Copy link
Author

sepple commented Jan 22, 2014

Of course. The store view switch works perfectly, but the locale does not. I set locale en_US as default, Store View international uses default and Store View German uses de_DE (overrides default) in system configuration. When i switch the store view to German, the locale isn't changed according to the configuration settings.
I don't know exactly what is going on, but i think that Magento\Core\Model\Locale::setLocale() is called without any arguments when initializing Mage, because this function then sets $this->_localeCode = $this->getDefaultLocale();
And this is exactly what happens. Locale is always the Default Locale, it doesn't use the Store View override.

@verklov
Copy link
Contributor

verklov commented Jan 23, 2014

Well, that's strange. Let me then create a ticket for this and place it to the backlog. Once the team looks at it, we will let you know of the investigation results.

@verklov
Copy link
Contributor

verklov commented Feb 4, 2014

@sepple , we had our team look at the issue.

Well, no good news for this particular issue... We could not reproduce it. Locales are switched on the frontend when changing store views as assigned in the backend. Below is the response from the team regarding your original message:

"Yes, in fact Magento\Core\Model\Locale::setLocale() is called without any arguments when initializing in the constructor. However, in the method itself, it inquires for a locale from the store configuration. Thus, if a locale set for the store is not default, it returns the locale set by you."

@sepple
Copy link
Author

sepple commented Feb 5, 2014

I inspected it again and the behaviour is actually slightly different than I wrote before.
It does not use the default config value for locale like I asserted, but it uses the setting of the first store view!

Scenarios:
Default value: en_US, 1st store view: de_DE, 2nd store view: uses default -> always de_DE
Default value: en_US, 1st store view: uses default, 2nd store view: uses default -> always en_US
Default value: de_DE, 1st store view: en_US, 2nd store view: de_DE -> always en_US
Default value: en_US, 1st store view: en_US, 2nd store view: de_DE -> always en_US

I'll try to figure out what's going wrong at my installation and report afterwards (if I'm able to).

@sepple
Copy link
Author

sepple commented Feb 6, 2014

@verklov I now traced it.

Magento\Module\Updater in function updateScheme()
$this->_appState->setUpdateMode(true);
... loop over module list ...
$this->_appState->setUpdateMode(false);

Important thing is Magento\App\State::$_updateMode == true while looping

When the loop arrives at Magento_Directory, couple of classes are instanciated, triggered by
Magento\Module\Updater\SetupFactory::create('directory_setup', 'Magento_Directory');

Using Magento\ObjectManager\ObjectManager, Magento\Interception\FactoryDecorator, Magento\ObjectManager\Factory\Factory, and Magento\ObjectManager\Factory\Factory::_resolveArguments(...) causing recursion following is instanciated:
Magento\Directory\Model\Resource\Setup
Magento\Directory\Helper\Data
Magento\Directory\Model\Resource\Country\Collection
Magento\Core\Model\Locale

Magento\Core\Model\Locale::__construct(...) is called with arg[9] = NULL, this is the locale. This function calls
Magento\Core\Model\Locale::setLocale(null), this calls
Magento\Core\Model\Locale::getDefaultLocale(), here it goes
$this->_coreStoreConfig->getConfig(\Magento\Core\Model\LocaleInterface::XML_PATH_DEFAULT_LOCALE)
Magento\Core\Model\Store\Config::getConfig($path, $store = null) returns $this->_storeManager->getStore($store)->getConfig($path); with
$this->_storeManager of type Magento\Core\Model\Store\Storage\Db
$store == null
$path = 'general/locale/code'

Following is interesting now:
Magento\Core\Model\Store\Storage\Db::getStore($storeId = null) at the very beginning:
if ($this->_appState->getUpdateMode()) {
return $this->_getDefaultStore();
}
Remember $this->_appState->getUpdateMode() is true!

$this->_getDefaultStore() simply returns $this-> _store when not empty.
line 370 protected function _initStores() actually sets $this-> _store to be the very first store of all stores with id > 0 (line 411)

That's what is happening at my installation. The locale is then available in the Locale class and never set again during lifetime of Locale. So it never is set with update mode false and locale is always the locale of the first store in store list.

@verklov
Copy link
Contributor

verklov commented Feb 10, 2014

@sepple , thanks for digging in the code! I will forward your investigation results to the team to look at the issue again.

@verklov
Copy link
Contributor

verklov commented Apr 23, 2014

@sepple, apparently we had such issue at the time you reported it. Having verified it on the most recent code, we cannot reproduce it any more. We are closing this issue.

@verklov verklov closed this as completed Apr 23, 2014
vpelipenko added a commit that referenced this issue Jul 20, 2015
magento-team pushed a commit that referenced this issue Mar 26, 2016
[Folks] Shipping Address and Method in Quote API
mmansoor-magento pushed a commit that referenced this issue Oct 7, 2016
Issues fixed:

- MAGETWO-54026 Automate Move a Store View to Another Store on the Same Website
- MAGETWO-55418 Variations and Constraints Review for automated functional tests in Store module
- MAGETWO-58260 Automate Frontend Customer Change Email
- MAGETWO-58261 Automate Frontend Customer Change Password
- MAGETWO-58354 Automate Block Cache Exploit
- MAGETWO-59432 Add missing constraints severity for cms module
- MAGETWO-57719 Intermittent HTTP ERROR 500 during checkout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants