Magento2: Language Switcher is not working on Magento 2.2.3

Created on 12 Apr 2018  路  26Comments  路  Source: magento/magento2


Preconditions


  1. Magento 2.2.3
  2. PHP 7.0.29

Steps to reproduce

  1. I had a Magento 2.2.1 with a website that has one store and two store's views (en and fr)
  2. On Stores -> Configuration -> Web , I set "Add Store code to URLs" to "YES"
  3. In front office, in the home page 'http://dev4.wetag.ca/) when I change the language it works. But when i'm in a different page such as "http://dev4.wetag.ca/index.php/en/name-tags.html" and i try to change the language from English to French it redirects back to the same URL.
  4. Since this was mentioned in here and it said it's been fixed in 2.2.2 I updated the Magento version from 2.2.1 to 2.2.3 and the problem is still there.

Expected result

  1. The store view changes when a user tries to, whether in the home page or in any other page on the website.

Actual result

  1. The store view only changes in the home page, in any other page, when the user tries to change the store view (the language) it doesn't work, it redirects back to the Home page with no errors.

Store Fixed in 2.1.x Cannot Reproduce Clear Description Confirmed Format is valid Ready for Work Reproduced on 2.3.x

Most helpful comment

My quickfix for a client now. Still have to do extensive testing.

\Magento\UrlRewrite\Model\StoreSwitcher\RewriteUrl::switch

        if ($oldRewrite) {

            $currentRewrites = $this->urlFinder->findAllByData([
                UrlRewrite::TARGET_PATH => $oldRewrite->getTargetPath(),
                UrlRewrite::STORE_ID => $targetStore->getId(),
            ]);

            if (null === $currentRewrites || empty($currentRewrites)) {
                /** @var \Magento\Framework\App\Response\Http $response */
                $targetUrl = $targetStore->getBaseUrl();
            } else {
                foreach($currentRewrites as $rewrite) {
                    $targetUrl = $targetStore->getBaseUrl() . $rewrite->getRequestPath();
                    break;
                }
            }
        }

All 26 comments

Same issue here, switcher only works on homepage

@mariamghalleb, thank you for your report.
We've acknowledged the issue and added to our backlog.

I can also reproduce this Issue on 2.2.5 CE and EE.

best regards,

Lars

Too sad that such core functionality does not work since 2.2.1...

Which guy solved this issue? I have a similar issue 2.2.2#16454; the same issue in 2.2.5

seems to be fixed in 2.2.6

@Cristiano81 Are you sure this is fixed in 2.2.6?

I just tried it and it still does not work correctly using different url_key for the same category for example.

yes,
I just tried it and it still does not work correctly using different url_key for the same category for example.

If I am looking at it correctly, it tries to lookup a url rewrite by using the old url and it only changes the store. I don't see how this could ever work unless all stores have the same url.

In version 2.2.5, it looks up a url rewrite by using the entity ID instead

Also it is redirecting twice for some reason, first to stores/store/redirect then to stores/store/switch, then to the actual url.

I'm having this same issue in v2.2.6, is there any temporary workarounds?

Facing same issue in v2.2.6. Common guys - anybody with temporary fix? It's a major issue for an ecommerce not being able to switch store view on a product page...

I can鈥檛 upgrade a Magento v2.2.2 site because it is a must-have feature switching languages for the product page.
I鈥檝e tried some modules to regenerate product and category urls hoping i could fix it but without success :-(

My quickfix for a client now. Still have to do extensive testing.

\Magento\UrlRewrite\Model\StoreSwitcher\RewriteUrl::switch

        if ($oldRewrite) {

            $currentRewrites = $this->urlFinder->findAllByData([
                UrlRewrite::TARGET_PATH => $oldRewrite->getTargetPath(),
                UrlRewrite::STORE_ID => $targetStore->getId(),
            ]);

            if (null === $currentRewrites || empty($currentRewrites)) {
                /** @var \Magento\Framework\App\Response\Http $response */
                $targetUrl = $targetStore->getBaseUrl();
            } else {
                foreach($currentRewrites as $rewrite) {
                    $targetUrl = $targetStore->getBaseUrl() . $rewrite->getRequestPath();
                    break;
                }
            }
        }

My quickfix

It works for me but not for static pages. Thanks, I鈥檒l make some other tests then I鈥檒l apply this quick fix as override in app/code

My quickfix

It works for me but not for static pages. Thanks, I鈥檒l make some other tests then I鈥檒l apply this quick fix as override in app/code

@teoteo

Yes this is only for routes that uses the url rewrites system / module. 'Static' urls and amasty modules are next on my list.

Any news on this issue? Facing the same issue on 2.2.7.

@waldok, there are currently 2 PR's open trying to fix this:

I can't find \Magento\UrlRewrite\Model\StoreSwitcher\RewriteUrl file in 2.2.5 CE ??

@raulsinapsis : it was added in 2.2.6 by https://github.com/magento/magento2/commit/32bca2b3d3cc54201477dc3b83e624808c30df8a#diff-72c711a978f42a0896e4615e7910c87e
Not sure if this is helpful.

And I know, this issue is very complex and has been attempted to be solved in many Magento versions in all kinds of different ways. Not sure if #19798 will solve all problems, but it looks pretty promissing.

Thanks @hostep
We've solved by upgrading 2.2.5 to 2.2.6 (then \Magento\UrlRewrite\Model\StoreSwitcher\RewriteUrl does exist) and then applying this PR https://github.com/magento/magento2/pull/20093

My quickfix for a client now. Still have to do extensive testing.

\Magento\UrlRewrite\Model\StoreSwitcher\RewriteUrl::switch

        if ($oldRewrite) {

            $currentRewrites = $this->urlFinder->findAllByData([
                UrlRewrite::TARGET_PATH => $oldRewrite->getTargetPath(),
                UrlRewrite::STORE_ID => $targetStore->getId(),
            ]);

            if (null === $currentRewrites || empty($currentRewrites)) {
                /** @var \Magento\Framework\App\Response\Http $response */
                $targetUrl = $targetStore->getBaseUrl();
            } else {
                foreach($currentRewrites as $rewrite) {
                    $targetUrl = $targetStore->getBaseUrl() . $rewrite->getRequestPath();
                    break;
                }
            }
        }

It works!!! Thank you!

the best fix to this issue just replace
___from_store
to
___store
in
vendor/magento/module-catalog/Controller/Product/View.php
and
vendor/magento/module-catalog/Controller/Category/View.php

My quickfix for a client now. Still have to do extensive testing.

\Magento\UrlRewrite\Model\StoreSwitcher\RewriteUrl::switch

        if ($oldRewrite) {

            $currentRewrites = $this->urlFinder->findAllByData([
                UrlRewrite::TARGET_PATH => $oldRewrite->getTargetPath(),
                UrlRewrite::STORE_ID => $targetStore->getId(),
            ]);

            if (null === $currentRewrites || empty($currentRewrites)) {
                /** @var \Magento\Framework\App\Response\Http $response */
                $targetUrl = $targetStore->getBaseUrl();
            } else {
                foreach($currentRewrites as $rewrite) {
                    $targetUrl = $targetStore->getBaseUrl() . $rewrite->getRequestPath();
                    break;
                }
            }
        }

Yes this Above Code only works for routes that uses the url rewrites system / module. but not for cms and static url So if you would like to resolve for static cms url then make below change Or Replace Below code in this file (\Magento\UrlRewrite\Model\StoreSwitcher\RewriteUrl::switch):

     if ($oldRewrite) {

        $currentRewrites = $this->urlFinder->findAllByData([
            UrlRewrite::TARGET_PATH => $oldRewrite->getTargetPath(),
            UrlRewrite::STORE_ID => $targetStore->getId(),
        ]);

        if (null === $currentRewrites || empty($currentRewrites)) {
            /** @var \Magento\Framework\App\Response\Http $response */
           $targetUrl = $redirectUrl
        } else {
            foreach($currentRewrites as $rewrite) {
                $targetUrl = $targetStore->getBaseUrl() . $rewrite->getRequestPath();
                break;
            }
        }
    }

Please check this Solution & Test All the Url in your site and let me know its Helpful to You.

Hi @mariamghalleb.

Thank you for your report and collaboration!

The related internal Jira ticket MAGETWO-93481 was closed as non-reproducible in 2.2.x.
It means that Magento team either unable to reproduce this issue using provided _Steps to Reproduce_ from the _Description section_ on clean or the issue has been already fixed in the scope of other tasks.

But if you still run into this problem please update or provide additional information/steps/preconditions in the _Description section_ and reopen this issue.

This was probably fixed by https://github.com/magento/magento2/pull/21140, which should be included in Magento 2.2.9 next week.
And it looks like it was already fixed in 2.3.1 by https://github.com/magento/magento2/pull/19798

So we can probably close this issue?

Thank you @hostep

Based on your https://github.com/magento/magento2/issues/14674#issuecomment-504473190
and absence of concerns during all this time, close this issue

Was this page helpful?
0 / 5 - 0 ratings