Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#11211 Fix Store View switcher #11337

Merged
merged 3 commits into from
Oct 31, 2017

Conversation

thiagolima-bm
Copy link
Member

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

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

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Oct 20, 2017

CLA assistant check
All committers have signed the CLA.

@@ -1166,6 +1166,9 @@ public function getCurrentUrl($fromStore = true)
if (!$this->isUseStoreInUrl()) {
$storeParsedQuery['___store'] = $this->getCode();
}
if ($this->getCode() !== $this->_storeManager->getStore()->getCode()) {

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


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

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)

$currentUrl .= $requestString;
}

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

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
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
Copy link

rsulym commented Feb 5, 2018

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

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