0

Since I have upgraded my website to Magento 2.2.0 (from 2.1.9), the store view switch stopped working on all the pages save for the homepage and the contact page.

I have 2 store views for 2 languages, and whenever I am on a page and I try to switch to the other language version of that page, I get a 404.

How to make this switcher work again?

1
  • The problem also persists when I disable my theme and use Luma, so the problem is not related to my theme.
    – Kawa
    Oct 31, 2017 at 11:40

3 Answers 3

0

As @mkotov writes.. the issue is tracked and solved.

For now, if you want, you could go in

magento2/app/code/Magento/Store/Model/Store.php (Magento installation by Github)

or

vendor/magento/module-store/Model/Store.php (Magento installation by composer)

and replace the second row in

public function getCurrentUrl($fromStore = true)

$requestString = $this->_url->escape(ltrim($this->_request->getRequestString(), '/'));

with

$requestString = $this->_url->escape(
    preg_replace(
        '/\?.*?$/',
        '',
        ltrim($this->_request->getRequestString(), '/')
    )
);
1

Issue is tracked internally under MAGETWO-80517 and will likely be included in 2.2.2 release. The root cause is that the ?___store=(store code) param is duplicated in the url when switching storeviews. You can remove the extra param manually to work-around the issue.

3
  • Can you please indicate how to remove it manually?
    – Kawa
    Nov 1, 2017 at 19:36
  • You should see it in the url. Manually remove it from the url in the browser.
    – mkotov
    Nov 3, 2017 at 3:07
  • Nope there isn't such parameter appearing in the URL. The URL is normally rewritten into what I've defined, it just leads to a 404 when I switch to the other language.
    – Kawa
    Nov 6, 2017 at 12:58
0

Find controller: Magento\Store\Controller\Store\Redirect, the issue might lie in the fact that the arguments are not passed along when going from Redirect in header links to the Switch controller:

$arguments = [
    '_nosid' => true,
    '_query' => $query
];
$this->_redirect->redirect($this->_response, 'stores/store/switch', $arguments);

Should become this:

$arguments = [
   '_nosid' => true,
   '_query' => $query
];
$arguments = array_merge($arguments,$this->_request->getParams());
$this->_redirect->redirect($this->_response, 'stores/store/switch', $arguments);

Of course here I am talking about making a module, hopefully nobody understands that you should work in core. Build an extension with this rewrite add this particular change and everything should work as expected.

This was the fix that worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.