Language handling once again

Dear community,
dear Marco!

I’ve seen many many people struggling with the problem that sometimes the shop
renders the wrong language.

I was debugging the 4.4.8 and the 4.8.4 and not because i only love the numbers 4 and 8
but i’ve to manage a 4.4.8 and i took a new release too.
This also doesn’t mean that this problem only affects this versions. Actually in 4.8.4 there is some “hack” to get rid of this problem, but lets see what i’ve found:

Take an oxid for example 4.4.8 EE or CE,
(or any above versions having the same problem)
Install any ssl cert for the site you testing, just to have “https” too.
Set your default language to English (Language ID 1)

Remove SEO URL for “index.php?cl=basket” for English language.

Ok. at this point you could ask, why should anyone remove existing SEO’s.
Its nonsense, but, its more easily to remove this SEO record for testing purposes
as adding a 3rd Language and forgot to fill up the SEO’s or leave them empty on purpose.

Register a user.
Open the shop, make sure that your selected language is English.
Log in and put something into the basket and go to checkout, go to step 2+ which has “https”.

In this point if you go back to step 1 (which has http, no ssl) the shop turns back to german.

Why:

oxlang::getBaseLanguage()

  1. there is no ‘changelang’ parameter.

  2. there is no ‘lang’ parameter. <- because of oxlang:: processurl() -> && ($iLang != oxRegistry::getConfig()->getConfigParam( ‘sDefaultLang’ )
    (at this point ‘sDefaultLang’ is 1, English)

  3. array of ‘aLanguageURLs’ is empty

  4. there is no ‘language’ in session

  5. there is no ‘language’ in cookie

  6. can’t detect language by browser

  7. at this point ‘sDefaultLang’ is 0 and 0 is language ID for german

It turns out, that because of the code mentioned under the 2. point does not allow
to put the “lang=1” parameter to the URL, because its the default lang id.
Meanwhile there is a change from https to http and every other trace of the selected language is wiped out and even ‘sDefaultLang’ turns to 0.

Remember, you have to turn out SEO’s, if smartys ‘oxgetseourl’ plugin finds any reference in the db, the language will be set correctly.

Now lets see the new version. 4.8.4.
For the first sight its seems to be ok but let’s play a bit around.
It was a bit tricky because my browsers default language is English, so i had to add a new language, ‘fr’.

Everything setted up the same as in 4.4.8, default language is fr (ID 3), no SEO for basket, added a new subdomain with ssl cert, opened the shop, french, login, put something in basket, checkout, step 2., step back, still french.

Well, i tought the boys had elminated the bug, lets see what did they do.
Debugging oxlang::getBaseLanguage() again.

  1. there is no ‘changelang’ parameter.

  2. there is no ‘lang’ parameter. (same reason)

  3. array of ‘aLanguageURLs’ is empty

  4. there is no ‘language’ in session

  5. there is ‘language’ in the cookie!

Well done! But what if i disable cookies?
config.inc.php => $this->blSessionUseCookies = false;

Again:

  1. there is no ‘changelang’ parameter.

  2. there is no ‘lang’ parameter. (same reason)

  3. array of ‘aLanguageURLs’ is empty

  4. there is no ‘language’ in session

  5. there is ‘language’ in the cookie!

Huh? No way, i’ve just diabled cookies.
Opening chrome cookie manager, and there were no “sid” no "sid_key"
BUT there is a lonely ‘language’.

This was the reason i called this a “hack”.

Now, just for sure i’ve deleted the ‘language’ cookie, - as i did not wanted cookies -
and made a refresh on the page:

  1. there is no ‘changelang’ parameter.
  2. there is no ‘lang’ parameter. (same reason)
  3. array of ‘aLanguageURLs’ is empty
  4. there is no ‘language’ in session
  5. there is no ‘language’ in the cookie
  6. language ‘english’ was detected by my browser, shop falls back to english.

I’m not sure that anyone on the earth could understand my post for the first read
but there are some questions need to be answered.

  1. is it necessary to trim the “lang=X” param from the url if default language is X?
    ( oxlang:: processUrl() )

  2. if yes, wouldn’t be practical to check whether the generated link would cause a
    protocol change http->https and vice versa, and leave the lang parameter on the url?

  3. how is it possible that oxid saves cookies meanwhile its disabled/not allowed!

Yours sincerely

[QUOTE=barthama;143275]
3. how is it possible that oxid saves cookies meanwhile its disabled/not allowed!
[/QUOTE]
Are you referring to blSessionUseCookies being set to false in your example? Well, the comment says this:

// Use browser cookies to store session id (no sid parameter in URL)

So this config param hasn’t got any effect for the language cookies but only for those cookies that store the session id.

Hm, good point, thanks, didn’t read the comment above.
This means 4.8.4 works as it should and there is no cookie-less mode.

Welcome again,

I found the problem in the older versions (Edit: the 4.4.8 was the last version with this “bug”):

in oxConfig::init() :

The session start “$this->getSession()->start();” will be called before loading the shop vars from db
"$this->_loadVarsFromDb( $sShopID );".

And getSession() calls oxConfig::getShopUrl()
which calls oxLang::getBaseLanguage()
which copies ‘sDefaultLang’ (0) into the cookie ‘language’
/* 0 => which was set in prior to session start in oxConfig::Init() */
which prevents oxLang::getBaseLanguage() to read ‘sDefaultLang’ again.

Unfortunately this is at the very beginnig of the shop startup, can’t be solved through overloading the init() function.

Edit: Patched through editing the source, oxconfig.php.

Yours sincerely

So this config param hasn’t got any effect for the language cookies but only for those cookies that store the session id.