magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.51k stars 9.31k forks source link

Language Switcher is not working on Magento 2.2.3 #14674

Closed mariamghalleb closed 4 years ago

mariamghalleb commented 6 years ago

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.
pablobae commented 6 years ago

Same issue here, switcher only works on homepage

ghost commented 6 years ago

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

larsroettig commented 6 years ago

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

best regards,

Lars

genyuk commented 6 years ago

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

realGomez commented 6 years ago

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

Cristiano81 commented 6 years ago

seems to be fixed in 2.2.6

nicobatty commented 6 years ago

@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.

samuel20miglia commented 6 years ago

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

domeglic commented 6 years ago

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.

cuiyang000 commented 5 years ago

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

budoland-ab commented 5 years ago

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...

teoteo commented 5 years ago

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

ghost commented 5 years ago

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;
                }
            }
        }
teoteo commented 5 years ago

My quickfix

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

ghost commented 5 years ago

My quickfix

It works for me but not for static pages. Thanks, I’ll make some other tests then I’ll 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.

waldok commented 5 years ago

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

hostep commented 5 years ago

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

raulsinapsis commented 5 years ago

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

hostep commented 5 years ago

@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.

raulsinapsis commented 5 years ago

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

xiaolinwuu commented 5 years ago

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!

megamosa commented 5 years ago

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

280690 commented 5 years ago

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.

magento-engcom-team commented 5 years ago

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.

hostep commented 5 years ago

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?

sdzhepa commented 4 years ago

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

magento-engcom-team commented 3 years ago

Hi @mariamghalleb.

Thank you for your report and collaboration!

The related internal Jira ticket MC-24558 was closed as Fixed.

The fix will be available with the upcoming 2.4.3 release.

tuyennn commented 3 years ago

@magento-engcom-team what is the status of this ticket, was this released? could you provide the related pull request

hostep commented 3 years ago

@tuyennn: does my comment above help?

These automated ticket updates by that bot are often incorrect, or maybe @sdzhepa can provide more info?

tuyennn commented 3 years ago

@hostep It's not, I'm able to replicate the issue on M 2.4.0-p1 for now.

hostep commented 3 years ago

@tuyennn: could you open a new issue with steps of how to reproduce the problem? The storeswitcher feature has been broken and fixed and broken again, many times in many different magento versions. So it could be a slightly different bug the the one in this thread.

tuyennn commented 3 years ago

@hostep Realized the hardcode 5s caused the problem https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Store/Model/StoreSwitcher/HashGenerator.php#L109

hostep commented 3 years ago

Ah right, you are talking about https://github.com/magento/magento2/issues/33042, okay, good to know!