Skip to content

#11211 Fix Store View switcher - #11337

Merged
magento-team merged 3 commits into
magento:2.2-developfrom
thiagolima-bm:fix#11211
Oct 31, 2017
Merged

magento-team merged 3 commits into
magento:2.2-developfrom
thiagolima-bm:fix#11211

Conversation

@thiagolima-bm

@thiagolima-bm thiagolima-bm commented Oct 10, 2017 •

Copy link
Copy Markdown
Member

Store View switcher not working on front-end and it throws an error #11211 #10908

@magento-cicd2

magento-cicd2 commented Oct 20, 2017 •

Copy link
Copy Markdown
Contributor

CLA assistant check
All committers have signed the CLA.

Comment thread app/code/Magento/Store/Model/Store.php Outdated
if (!$this->isUseStoreInUrl()) {
$storeParsedQuery['___store'] = $this->getCode();
}
if ($this->getCode() !== $this->_storeManager->getStore()->getCode()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thiagolima-bm Please explain why usage of __from_store query parameter should be used.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for tracking, maybe?

Comment thread app/code/Magento/Store/Model/Store.php Outdated

//avoid query params duplication
if (!preg_match('/___store=(.*?)&___from_store=(.*?)/', $requestString)) {
$currentUrl .= $requestString;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$requestCode also contains path and this data may be lost

STR:

  • go to Privacy and Cookie Policy
  • switch store view (store view switched, user still on Privacy and Cookie Policy)
  • switch store view again (store view switched, user on main page but should be on Privacy and Cookie Policy)

Comment thread app/code/Magento/Store/Model/Store.php Outdated
$currentUrl .= $requestString;
}

$currentUrl .= ($storeParsedQuery ? '?' . http_build_query($storeParsedQuery, '', '&') : '');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the source of the issue is concatenation with ? while $requestString may contain query. To fix this I propose:

  1. Split $requestString into path and query:
$requestStringParts = explode('?', $requestString, 2);
$requestStringPath = $requestStringParts[0];
if (isset($requestStringParts[1])) {
   parse_string($requestStringParts[1], $requestStringQuery);
} else {
    $requestStringQuery = []
}
  1. Merge original query params and store parsed query
$currentUrlQueryParams = array_merge($requestStringQuery, $storeParsedQuery);
  1. Safely concatenate all parts of url:
$currentUrl = $storeParsedUrl['scheme']
    . '://'
    . $storeParsedUrl['host']
    . (isset($storeParsedUrl['port']) ? ':' . $storeParsedUrl['port'] : '')
    . $storeParsedUrl['path']
    . $requestStringPath
    . ($currentUrlQueryParams ? '?' . http_build_query($currentUrlQueryParams, '', '&') : '');

@thiagolima-bm

Copy link
Copy Markdown
Member Author

@vkublytskyi fixes applied.

@magento-team
magento-team merged commit 84729b5 into magento:2.2-develop Oct 31, 2017
magento-team pushed a commit that referenced this pull request Oct 31, 2017
[EngCom] Public Pull Requests - 2.2-develop
 - MAGETWO-82955: [Backport 2.2-develop] FIX show visual swatches in admin - product attribute #11747
 - MAGETWO-82943: Magetwo 70954: Remove the component.clear from the custom options type. This causes the 'elem' array to become out of sync with the recordData #11824
 - MAGETWO-82710: Fix issue #10032 - Download back-up .tgz always takes the latest that's created (2.2-develop) #11595
 - MAGETWO-81994: Products added to cart with REST API give total prices equal to zero #11458
 - MAGETWO-81422: #11211 Fix Store View switcher #11337
@magento-engcom-team magento-engcom-team added Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release hacktoberfest labels Dec 22, 2017
@rsulym

rsulym commented Feb 5, 2018

Copy link
Copy Markdown

Gents, still not able to manage this issue to get it work ((
Version 2.2.1, cannot upgrade to 2.2.2
Is this file (Store.php) is complete fix which i need?
https://github.com/thiagolima-bm/magento2/blob/84729b581638e00459fcca63bb6d7a1c77f252b9/app/code/Magento/Store/Model/Store.php

altdovydas pushed a commit to altdovydas/magento2 that referenced this pull request Aug 6, 2026
Applied pull request patch https://github.com/magento/magento2/pull/11337.patch (created by @thiagolima-bm) based on commit(s):
  1. ce4fb97
  2. beccd7d
  3. 84729b5

Fixed GitHub Issues in 2.3-develop branch:
  - magento#10908: [2.2.0-rc3.0] Language switcher is broken when using multiple times (reported by @hostep)
  - magento#11211: Store View switcher not working on front-end and it throws an error (reported by @latypatil)
altdovydas pushed a commit to altdovydas/magento2 that referenced this pull request Aug 6, 2026
Applied pull request patch https://github.com/magento/magento2/pull/11337.patch (created by @thiagolima-bm) based on commit(s):
  1. ce4fb97
  2. beccd7d
  3. 84729b5

Fixed GitHub Issues in 2.3-develop branch:
  - magento#10908: [2.2.0-rc3.0] Language switcher is broken when using multiple times (reported by @hostep)
  - magento#11211: Store View switcher not working on front-end and it throws an error (reported by @latypatil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Award: complex Release Line: 2.2 Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants