Skip to content

[2.2.0-rc3.0] Language switcher is broken when using multiple times #10908

Closed

Description

@hostep

Preconditions

  1. PHP 7.0.22

Steps to reproduce

  1. Install Magento CE 2.2.0-rc3.0 using composer
  2. Switch to developer mode
  3. In the backend, make sure you have 2 storeviews (in my example: Dutch & English)
  4. Reindex & flush caches
  5. Load the frontend
  6. Using the language switcher in the header, switch from the default storeview (Dutch in my example) to English, the url changes to: https://example.com/?___store=en
  7. Using the language switcher in the header, switch again from English to Dutch, the url changes to: https://example.com/?___store=en?___store=nl and the shop crashes

Expected result

  1. The url should be https://example.com/?___store=nl and the shop shouldn't crash

Actual result

  1. The url is https://example.com/?___store=en?___store=nl and the shop crashes with the message:
1 exception(s):
Exception #0 (Magento\Framework\Exception\NoSuchEntityException): Requested store is not found

Exception #0 (Magento\Framework\Exception\NoSuchEntityException): Requested store is not found
#0 vendor/magento/module-store/Model/StoreManager.php(168): Magento\Store\Model\StoreRepository->get('en?___store=nl')
#1 vendor/magento/module-store/App/Action/Plugin/Context.php(85): Magento\Store\Model\StoreManager->getStore('en?___store=nl')
#2 vendor/magento/framework/Interception/Interceptor.php(121): Magento\Store\App\Action\Plugin\Context->beforeDispatch(Object(Magento\Cms\Controller\Index\Index\Interceptor), Object(Magento\Framework\App\Request\Http))
#3 vendor/magento/framework/Interception/Interceptor.php(153): Magento\Cms\Controller\Index\Index\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#4 generated/code/Magento/Cms/Controller/Index/Index/Interceptor.php(39): Magento\Cms\Controller\Index\Index\Interceptor->___callPlugins('dispatch', Array, Array)
#5 vendor/magento/framework/App/FrontController.php(55): Magento\Cms\Controller\Index\Index\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#6 vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#7 vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#8 vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php(94): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#9 vendor/magento/framework/Interception/Interceptor.php(135): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#10 vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php(73): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#11 vendor/magento/framework/Interception/Interceptor.php(135): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#12 vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#13 generated/code/Magento/Framework/App/FrontController/Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, NULL)
#14 vendor/magento/framework/App/Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#15 vendor/magento/framework/App/Bootstrap.php(256): Magento\Framework\App\Http->launch()
#16 pub/index.php(37): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#17 {main}

Discussion

This was only very recently broken, in commit: c3ea1f5, the changes in the file lib/internal/Magento/Framework/App/Request/Http.php cause this.

Also: please change this typo from removeRepitedSlashes to removeRepeatedSlashes, so this method has the same name as in Magento 2.1

Possible solution

If we change this line from:

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

to:

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

It works again as expected, but I'm not sure yet if this is the correct solution.

Activity

  1. magento-engcom-team commented on Sep 19, 2017

    @magento-engcom-team
    Contributor

    @hostep thank you for your bug report.
    We've created internal ticket MAGETWO-75448 to track progress on the issue.

  2. vrootwoot commented on Sep 26, 2017

    @vrootwoot

    Apparently the issue only occurs from the homepage, starting working on it.

  3. BlackIkeEagle commented on Sep 26, 2017

    @BlackIkeEagle
    Member

    @vrootwoot you still working on this? I have this issue too while I'm working on some other issue in the store switcher

  4. vrootwoot commented on Sep 26, 2017

    @vrootwoot

    @BlackIkeEagle won't have the time to fix it.

    Apparently correct way would be to add changes to getTargetStorePostData
    in app/code/Magento/Store/Block/Switcher.php.
    And also change the entry points in the Switcher Block as well.

  5. LuisChaves commented on Oct 8, 2017

    @LuisChaves

    In addition to changing the line of code suggested by hostep, to also remove "?___ store". Change line 228 "$store->getCurrentUrl(false)," to "$this->getUrl ('stores/store/switch' ), "from the file" module-store \ Block \ Switcher.php "

  6. added
    Issue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmed
    Reproduced on 2.2.xThe issue has been reproduced on latest 2.2 release
    and removed on Oct 11, 2017
  7. selusi commented on Oct 13, 2017

    @selusi

    However, the bug is much more complex, because if you change the language on page of the product details or on a category page the app give a not found page, because does not translate the urlrewrite.
    In the previous version Magento 2.1.9 the switcher worked fine.

  8. 1 remaining item

  9. hostep commented on Oct 14, 2017

    @hostep
    ContributorAuthor

    @selusi: just FYI, you've changed the code back to how it was before commit 508f1ef, in this commit, they fixed the storeswitcher when you work with multiple domain names since it used to store the wrong store code in a cookie which has as a result that we ended up in an endless redirect from one domain name to the other.
    It might be worth to test if it still works when switching stores with multiple domain names if you revert that line back to $this->getUrl('stores/store/switch'), but I have the feeling that the original problem will be back if you do this.

    (unrelated, but this page might be worth checking out for formatting your comments on github a bit better: https://guides.github.com/features/mastering-markdown/, please check the 'code' tab in the Examples 😉)

  10. selusi commented on Oct 14, 2017

    @selusi

    @hostep Thank you for the clarification. I apologize, because I did not read the commit 508f1ef you rightly mentioned.
    So everything is again in question, because your code solve only a part of issue.

  11. thiagolima-bm commented on Oct 26, 2017

    @thiagolima-bm
    Member
  12. okorshenko commented on Oct 31, 2017

    @okorshenko
    Contributor

    the issue has been fixed and delivered to 2.2-develop branch. WIll be available with 2.2.2 release

  13. magento-engcom-team commented on Jan 30, 2018

    @magento-engcom-team
    Contributor

    Hi @hostep. Thank you for your report.
    The issue has been fixed in magento-engcom/magento2ce#1285 by @magento-engcom-team in 2.3-develop branch
    Related commit(s):

    The fix will be available with the upcoming patch release.

  14. mariamghalleb commented on Apr 12, 2018

    @mariamghalleb

    @magento-engcom-team the link doesn't work ..

  15. MrDaar commented on Apr 25, 2018

    @MrDaar

    It's not good code, and it's not thoroughly tested, but here's a temp fix if you're currently experiencing this issue:

    <type name="Magento\Store\Block\Switcher">
        <plugin name="Vendor_Module_Plugin_Magento_Store_Block_Switcher"
                type="Vendor\Module\Plugin\Magento\Store\Block\Switcher"
                sortOrder="0"
        />
    </type>
    
    <?php
    namespace Vendor\Module\Plugin\Magento\Store\Block;
    
    class Switcher
    {
        /**
         * Returns target store post data
         *
         * @see https://github.com/magento/magento2/issues/10908
         * @param \Magento\Store\Block\Switcher $subject
         * @param string $postData
         * @return string
         */
        public function afterGetTargetStorePostData(
            \Magento\Store\Block\Switcher $subject,
            $postData
        ) {
            $data = json_decode($postData, true);
    
            if (empty($data['action'])) {
                return $postData;
            }
    
            if (substr_count($data['action'], '___store') < 2) {
                return $postData;
            }
    
            $data['action'] = preg_replace('/___store=(.*?)___store/', '___store', $data['action']);
    
            return json_encode($data);
        }
    }
    

    Let me know if it works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.2.xThe issue has been reproduced on latest 2.2 release

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions