Skip to content

Magento2 Switches back to Default Storeview eachtime I change page #6404

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

Closed
Sid-95 opened this issue Aug 30, 2016 · 21 comments
Closed

Magento2 Switches back to Default Storeview eachtime I change page #6404

Sid-95 opened this issue Aug 30, 2016 · 21 comments

Comments

@Sid-95
Copy link

Sid-95 commented Aug 30, 2016

Magento2 Switches back to Default Storeview eachtime I change page

I've setted up my magento store @ the following link (http://162.252.104.103/), i successfully added 2 storeviews. One with italian language (default) & one with eng lang.
When I switch to eng lang it works fine, but if I do any action it reverts back to the default storeview (italian lang). I checked several thing, and I noticed that when I change the storeview no cookie related to storeview setted. But I can't figure out why this isn't working

Preconditions

  1. Magento2 Running Ultimo theme
  2. 1 Website, 1 Store, 2 Storeview (italian & lang views)

Steps to reproduce

  1. Install Magento2
  2. Create 2 storeview
  3. Switch from one to another
  4. Change page

Expected result

  1. Magento should remember the storeview selected and keep the language selection

Actual result

  1. Magento reverts back to the default storeview
@veloraven
Copy link
Contributor

@Sid-95 thank you for your report.
Please, provide the used version. If the problem is actual for a specific tag, please, specify it and be sure that the latest update was used.
Please also provide more detailed steps as it is not clear where you switch from one store view to another. And what do you mean as 'change page'. So please write steps in the format like 'click...', 'select...'

@Sid-95
Copy link
Author

Sid-95 commented Aug 31, 2016

@veloraven Thanks for your answer, I am using Magento 2.1.0

I switch from one storeview to the other using the storeview switcher (which appears in my store with languages icon & label).

Here's the step to reproduce the bug on my site:

  • I Open the store at http://162.252.104.103/
  • I click on the top right storeview switcher and select the english storeview (default is italian's one)
  • Magento shows me the page I was browsing in english storeview and works fine.
  • I navigate to a whatever other page for example I open My Account

Expected result
Magento should remember that I am using eng storeview, so show me the page in english

Actual result
Magento switches back to default storeview (italian language)

Annotations
When I select the eng storeview and check HTTP header I expected to see a SetCookie where storeview was setted but there's no cookie like that.

@picamator
Copy link

picamator commented Sep 6, 2016

@Sid-95 Thanks for reporting.
Unfortunately we cannot reproduce that issue.

We have followed those steps:

  1. Installed Magento 2.1.0
  2. Installed language package
  3. Used default theme "Luma"
  4. Created new Store View e.g. "English Store View"
  5. Configured "Default Store View" locale to Italian (Italy)
  6. Refreshed all invalid cache using System->Cache Management
  7. Open front-end page
  8. Switch to "English Store View"
  9. Go "Create an Account"
  10. Created new account
  11. Switch to "Default Store View"
  12. Go to main page
  13. Switch to "English Store View"
  14. Go to "My account"
    15 Go to main page

In those steps language was preserved and related to corresponding store view.

  1. Could you please try steps above to see how it's working?
  2. Do you have any specifics steps that are not covered ours?
  3. What is a history change for locales in your store views?
    E.g. Firstly you have create "Italy store view" with Italian (Italy) locale,
    then rename it to "English Store View" and change locale to English (United States), then change locale for "Default Store View" to Italian (Italy).

@Sid-95
Copy link
Author

Sid-95 commented Sep 6, 2016

@picamator this is the link: texbook.it

Here what I've done:

  • Installed magento
  • Installed theme Ultimo
  • setted up all basic things
  • Created new storeview (Italian)
  • When to homepage
  • Switched storeview
  • Navigated to create new account
  • Magento reverted default storeview

Maybe is something with cookie that I am missing

@ronnybremer
Copy link

I can confirm the same behaviour with CE 2.1.1.
We have a default store view of German set for the store and also provide an English view. When changing language through the language picker, the URL gets changed as follows:
http://shop.example.com/magento2/contact/?___store=sv_en&___from_store=sv_de
and the user is redirected. The page is shown in English.

The next action will immediately bring you back to the German view store, for example:
I click on the menu to go to a specific category. The URL sent to the server is:
http://shop.example.com/magento2/category1.html
which is part of the English shop, just as expected. The server gets the request but redirects the user to:
http://shop.example.com/magento2/kategorie1.html
which is the same category but with its German URL.

We are using SEO and mod_rewrite, so each category has a different SEO URL in every language.

As Sid-95 did mention, there doesn't seem to be a language cookie set, I can see the same here on my end. But I would expect the PHP session to remember the current language selection of the user.

@ronnybremer
Copy link

I forget to mention, this is a clean install of CE 2.1.1 on CentOS 7, running with a 2.4 apache server on PHP 5.6.25. Alle caches are disabled and we are in development mode.

@ronnybremer
Copy link

ronnybremer commented Sep 8, 2016

Some observation from a TCP trace.
The issue seems to be related to the cookie: "store". When browsing the German view, the cookie is set to "sv_de". Now when running through my example from above, this is the request trying to switch to English:

GET /magento2/category1.html?___store=sv_en&_from_store=sv_de HTTP/1.1
Host: store.example.com
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,
/
;q=0.8
Connection: keep-alive
Cookie: PHPSESSID=anif6bii3uhtfh4fcqsbom7ja5; form_key=xKzLnN9a28eCz8L8; store=sv_de; mage-translation-file-version=%7B%7D; mage-translation-storage=%7B%7D; X-Magento-Vary=373dd70786fa45a3c6ccb0873765feb0e8f3b574; __atuvc=2%7C9; m2e_bn_06639d28d8=1; m2e_bn_215f57f170=1; m2e_bn_304033419c=1; m2e_bn_398801d0fc=1; m2e_bn_44c5613270=1; m2e_bn_4c9e472954=1; m2e_bn_5300762365=1; m2e_bn_5d4712fed7=1; m2e_bn_6251bd2848=1; m2e_bn_76690df5bf=1; m2e_bn_77a7d89089=1; m2e_bn_924b46ec46=1; m2e_bn_9389a5df36=1; m2e_bn_956e9bb04d=1; m2e_bn_a4ca91b9ed=1; m2e_bn_b793c03216=1; m2e_bn_bc22baa29e=1; m2e_bn_d169b1b787=1; m2e_bn_d605d3c436=1; m2e_bn_df921d344a=1; m2e_bn_e3770150d0=1; m2e_bn_e8b67ccb7d=1; m2e_bn_f25faa424a=1; mage-cache-sessid=true; mage-cache-storage=%7B%7D; mage-cache-storage-section-invalidation=%7B%7D; IPCZQX03a36c6c0a=0100ce00ac190332a147980c8683cad3226e2f11; _ga=GA1.2.259634623.1465205264; ck_login_id_20=9ad43802-9f80-7f4e-1fb5-451138df4e1d

It does request the correct URL and the cookie "store" is still set to the German view, all good.

Now the server responds:

HTTP/1.1 302 Found
Date: Thu, 08 Sep 2016 06:40:13 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod_fcgid/2.3.9 PHP/5.6.25
X-Powered-By: PHP/5.6.25
Expires: Tue, 08 Sep 2015 06:40:15 GMT
Cache-Control: max-age=0, must-revalidate, no-cache, no-store
Pragma: no-cache
Set-Cookie: X-Magento-Vary=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; httponly
Location: category1.html
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Access-Control-Allow-Origin: *
X-UA-Compatible: IE=edge
Content-Length: 0
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8

As you can see, the Location is still set to the English category name, but the cookie "store" is not transferred, hence the client will now issue the following request:

GET /magento2/category1.html HTTP/1.1
Host: store.example.com
Cookie: PHPSESSID=anif6bii3uhtfh4fcqsbom7ja5; form_key=xKzLnN9a28eCz8L8; store=sv_de; mage-translation-file-version=%7B%7D; mage-translation-storage=%7B%7D; __atuvc=2%7C9; m2e_bn_06639d28d8=1; m2e_bn_215f57f170=1; m2e_bn_304033419c=1; m2e_bn_398801d0fc=1; m2e_bn_44c5613270=1; m2e_bn_4c9e472954=1; m2e_bn_5300762365=1; m2e_bn_5d4712fed7=1; m2e_bn_6251bd2848=1; m2e_bn_76690df5bf=1; m2e_bn_77a7d89089=1; m2e_bn_924b46ec46=1; m2e_bn_9389a5df36=1; m2e_bn_956e9bb04d=1; m2e_bn_a4ca91b9ed=1; m2e_bn_b793c03216=1; m2e_bn_bc22baa29e=1; m2e_bn_d169b1b787=1; m2e_bn_d605d3c436=1; m2e_bn_df921d344a=1; m2e_bn_e3770150d0=1; m2e_bn_e8b67ccb7d=1; m2e_bn_f25faa424a=1; mage-cache-sessid=true; mage-cache-storage=%7B%7D; mage-cache-storage-section-invalidation=%7B%7D; IPCZQX03a36c6c0a=0100ce00ac190332a147980c8683cad3226e2f11; _ga=GA1.2.259634623.1465205264;

Still all cool, but as you can see in the request, the cookie "store" is still set to the German view and now the server doesn't have any clue anymore, that we actually wanted the English view, so of course it will reply with:

HTTP/1.1 301 Moved Permanently
Date: Thu, 08 Sep 2016 06:40:15 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod_fcgid/2.3.9 PHP/5.6.25
X-Powered-By: PHP/5.6.25
Expires: Tue, 08 Sep 2015 06:40:16 GMT
Cache-Control: max-age=0, must-revalidate, no-cache, no-store
Pragma: no-cache
Location: http://store.example.com/magento2/kategorie1.html
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Access-Control-Allow-Origin: *
X-UA-Compatible: IE=edge
Content-Length: 0
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8

So back to German it is.

I do assume, that in the "HTTP/1.1 302 Found" reply from the server, the cookie "store" should have been changed to "sv_en".

Ronny

@ronnybremer
Copy link

There was another (now closed) issue related to the "store" cookie value. Maybe they are related?
https://github.com/magento/magento2/issues/3676

@picamator
Copy link

Thank you for details,
But we still cannot reproduce it.

@Sid-95 , we have:

  1. went to http://it.texbook.it/
  2. switched to English
  3. went to "Create account"
    as a result we have seen English page. The only thing in Italian is "Contattaci" on the top menu.

Could you please clear all Browser Storage: Cache, Cookies, Session Storage, Local Storage?
And let us know how it's working.

@ronnybremer

  1. Could you please provide information, what configuration, customization you set to get __store and __from_store in your url?

@Sid-95
Copy link
Author

Sid-95 commented Sep 8, 2016

@picamator actually I solved it by adding virtual sub dom, and separating eng storeview in subdomain en.texbook.it & italian in it.texbook.it. Yes it's very ugly to see a .IT domain with subdomain en. But that's a thing a we are going to change & it's out of scope.

In my guess it's something related to hardcoded linking

@ronnybremer
Copy link

ronnybremer commented Sep 8, 2016

@picamator Thank you for your response, it pointed me in the right direction. The culprit was found in the template we are using, for the language switcher the following code was used as the anchor inside the foreach loop to generate the drop down box:
<a href="<?php echo $_lang->getCurrentUrl(); ?>">

This might have worked in older versions of Magento, but doesn't seem to work in 2.1.
I replace it with the following code:
<a href="#" data-post='<?php echo $this->getTargetStorePostData($_lang); ?>'>
and now it works reliably on all sub pages I have tested so far.

Maybe this should be part of a FAQ for theme developers, if it isn't already.

Thank you for your time and assistance, from my perspective the issue can be closed.

Yours,

Ronny

@picamator
Copy link

@ronnybremer @Sid-95 We glad to hear that issue was solved. Please feel free to reopen it if you need.

@davideghz
Copy link

davideghz commented Dec 14, 2016

Hi, same issue here with a theme that uses the "old"
<a href="<?php echo $_lang->getCurrentUrl(); ?>">.

Now, if I replace it with
<a href="#" data-post='<?php echo $this->getTargetStorePostData($_lang); ?>'>

I get the following error:

section-config.js:33 Uncaught TypeError: Cannot read property '*' of undefined(…)

@dimple-vasoya
Copy link

I am also facing the same issue. It shows different store in the cookie. Please suggest the solution.

@ctadlock
Copy link

ctadlock commented Jan 4, 2017

The solution provided here (#3676 (comment)) resolved the issue for me. I still have an open question as to why this isnt being included in the Magento code.

@maderlock
Copy link

If the "fix" from #3676 was included then it would break the standard store switcher that replies on cookies overriding server settings. The standard approach is for the server to set a default store, and then your cookie determines whether a different store is used.

@zeeshan2523806
Copy link

@ronnybremer solutions worked for me.

@fordiy
Copy link

fordiy commented Mar 21, 2017

@ronnybremer solutions worked for me too.
I want to say to Magento: Who make this totally chaos CMS? Waste developers' time. Why this shit still in the market. Everything it makes so complicated but NOT good as Joomla or OpenCart. Just a language & currency will cost you two more Days. If in Joomla, just 2 hours done!

@thomasnordkvist
Copy link

@ronnybremer your solution worked for me. Thank you

@kleverk-Designs
Copy link

Hello,

I am facing the same issue. I have 2 store views one Telegu and other English.

When i am using English language store view and try to click any menu or any link it redirects to default store view.

When i switch from telegu language to english My site url displays like this http://bharatka.nextmp.net/mobiles-and-accessories.html?___store=kleverk&___from_store=default

I tried using this code in pub index.php but it does not work #3676

Any advice how to fix this.

Thanks

@michel334
Copy link

same issue in 2.3.3

magento-engcom-team pushed a commit that referenced this issue Dec 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests