Hello,
Looks like there is an issue with store views switching on Magento 2 on the frontend, when "Add Store Code to Urls" option is enabled.
When the option is enabled, store views switcher will get stuck and I won't be able to switch to another store view.
I attached a gif image to show you how to reproduce it. Thanks.
(In the gif, cache is disabled on the website. I also tested with cache enabled)

Hi,
just took a quick look and need some rechecks but from what I saw:
I think that Magento\Store\Controller\Store\SwitchAction does not consider this option, or I am not able to see this.
A possible solution could be, to add a check into the Controllers execute method.
Example solution SwitchAction->execute()
$redirectUrl = $this->_redirect->getRedirectUrl();
if($store->isUseStoreInUrl())
{
$redirectUrl = $store->getBaseUrl();
}
$this->getResponse()->setRedirect($redirectUrl);
This would allow to redirect to the correct url.
As I just said, just did some quick tests and it works but I think I should make further checks to be 100% sure.
If you like I can pass a PR for this.
Best
Hello, i tested this fix and apparently it works
But, when you switch from any page but the home page, it brings you to the home page and not to the store view of the item you were on.
Ex. mystore.test/it/prodotto.htm does not go to mystore.test/en/product.htm but to mystore.test/en/
S
An addition to the above comment:
The behaviour (reset to base url when switching language) happens from any item, be it csm page, product or category when Store Code Urls is active.
If I get the chance I will take a deeper look. This last one was just a quick shot, which was not tested thoroughly. I think I'll go ahead and make a full PR next week.
Same problem here with Magento 2.0.1 EE
Same problem here with Magento 2.0.2
Any chance to fix it?
For me also same problem with Magento 2.0.2
Thank you all, we have created MAGETWO-51294 to investigate and fix.
Same issue on EE
@coolshot Could you please explain your observations a little further? The way were thinking about fixing this is very close to what @xhallix said. I am able to switch between store views without any problem after the fix. No redirection to default store view when switching from one to anther.
Take a look at patch: http://pastebin.com/s9anwxhv
@hshar7 gonna test it over the weekend and post feedback, thank you
@coolshot awesome, thanks!
@hshar7 i just tested, works well apparently, on the home page.
The issue that remains is that wherever you are, when you switch store view, it brings to the the home page instead of the original page version for the destination store view,
Real case example :
I set up one category named "_Components_", the name and url key for the views are
en-> _components_
fr-> _composants_
it-> _componenti_
If you browse the "en" _mysite.com/en/components_ and switch to "fr" store view it loads _mysite.com/fr/_ and not _mysite.com/fr/composants_ as i would expect
Guess it's not completely solved, but it seems a start and since i guess a normal user would rarely need to switch from one view to the other outside of the home page, it might be enough to allow a real world use for those who need a multilanguage shop.
Thanks :+1:
thank you @coolshot I made sure to take care of that case also. Fix should be up on develop soon!
@moe-kayali Thank you for reporting the issue. Fix for MAGETWO-51294 merged to develop branch.
The fix is not on Magento 2.0.7 yet!!!!
Hi,
Is this fix into 2.0.9?
Last time i checked it was, but i don't remember if it was the release you
mention as i am busy on something else and i am not spending time on
magento atm :)
2016-08-13 22:17 GMT+02:00 lucasalfaro [email protected]:
Hi,
Is this fix into 2.0.9?—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/magento/magento2/issues/2786#issuecomment-239639504,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AMkuRVDZ-_ll03SIell1hlHfQAMrU4z0ks5qfiZbgaJpZM4G55J7
.
I have encountered the same problem in the 2.2.1. Store view switch works on home page, but redirects to the default store view on any other page.
same problem on 2.2.3
Same on 2.2.5
It seems that Magento added following plugin in 2.2.5: vendor/magento/module-catalog-url-rewrite/Plugin/Store/Block/Switcher.php
Which specifically targets catalog pages and that's why product redirect isn't working.
If I disable that plugin by writing following in di.xml:
<type name="\Magento\Store\Block\Switcher">
<plugin name="store_switcher_plugin" disabled="true"/>
</type>
Then switching stores in product view again works. ( I'm redirected to the same product instead of homepage )
When inspecting store switcher elements html, I saw that data-post attribute for .view-latvian switcher-option a element was pointing to the homepage in 2.2.5 version. In 2.2.3 it was pointing to the same product url that you are currently on. After disabling that plugin, it again points to the same products url.
Could Magento team check this?