From ce4fb9740ec8a362f77110ff9755f871d5187fdd Mon Sep 17 00:00:00 2001 From: Thiago Lima Date: Tue, 10 Oct 2017 13:43:37 +0200 Subject: [PATCH 1/3] #11211 Fix Store View switcher --- app/code/Magento/Store/Model/Store.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Store/Model/Store.php b/app/code/Magento/Store/Model/Store.php index 1d100da274465..f9db40c05a332 100644 --- a/app/code/Magento/Store/Model/Store.php +++ b/app/code/Magento/Store/Model/Store.php @@ -1166,6 +1166,9 @@ public function getCurrentUrl($fromStore = true) if (!$this->isUseStoreInUrl()) { $storeParsedQuery['___store'] = $this->getCode(); } + if ($this->getCode() !== $this->_storeManager->getStore()->getCode()) { + $fromStore = true; + } if ($fromStore !== false) { $storeParsedQuery['___from_store'] = $fromStore === true ? $this->_storeManager->getStore()->getCode() : $fromStore; @@ -1175,9 +1178,14 @@ public function getCurrentUrl($fromStore = true) . '://' . $storeParsedUrl['host'] . (isset($storeParsedUrl['port']) ? ':' . $storeParsedUrl['port'] : '') - . $storeParsedUrl['path'] - . $requestString - . ($storeParsedQuery ? '?' . http_build_query($storeParsedQuery, '', '&') : ''); + . $storeParsedUrl['path']; + + //avoid query params duplication + if (!preg_match('/___store=(.*?)&___from_store=(.*?)/', $requestString)) { + $currentUrl .= $requestString; + } + + $currentUrl .= ($storeParsedQuery ? '?' . http_build_query($storeParsedQuery, '', '&') : ''); return $currentUrl; } From beccd7dd47b6d8421cb50863acb476d9b9bcec4b Mon Sep 17 00:00:00 2001 From: Thiago Lima Date: Fri, 20 Oct 2017 10:37:38 +0200 Subject: [PATCH 2/3] #11211 Fix Store View switcher, update integration test --- .../integration/testsuite/Magento/Store/Model/StoreTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/Store/Model/StoreTest.php b/dev/tests/integration/testsuite/Magento/Store/Model/StoreTest.php index e62436460998f..67fe8d1dedea9 100644 --- a/dev/tests/integration/testsuite/Magento/Store/Model/StoreTest.php +++ b/dev/tests/integration/testsuite/Magento/Store/Model/StoreTest.php @@ -274,7 +274,7 @@ public function testGetCurrentUrl() $this->model->load('admin'); $this->model->expects($this->any())->method('getUrl')->will($this->returnValue('http://localhost/index.php')); $this->assertStringEndsWith('default', $this->model->getCurrentUrl()); - $this->assertStringEndsNotWith('default', $this->model->getCurrentUrl(false)); + $this->assertStringEndsWith('default', $this->model->getCurrentUrl(false)); } /** From 84729b581638e00459fcca63bb6d7a1c77f252b9 Mon Sep 17 00:00:00 2001 From: Thiago Lima Date: Sat, 21 Oct 2017 14:03:51 +0200 Subject: [PATCH 3/3] #11211 Fix Store View switcher, undo integration test changes and refactory --- app/code/Magento/Store/Model/Store.php | 25 +++++++++++-------- .../Magento/Store/Model/StoreTest.php | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/Store/Model/Store.php b/app/code/Magento/Store/Model/Store.php index f9db40c05a332..c7d226eec8cf3 100644 --- a/app/code/Magento/Store/Model/Store.php +++ b/app/code/Magento/Store/Model/Store.php @@ -1166,26 +1166,29 @@ public function getCurrentUrl($fromStore = true) if (!$this->isUseStoreInUrl()) { $storeParsedQuery['___store'] = $this->getCode(); } - if ($this->getCode() !== $this->_storeManager->getStore()->getCode()) { - $fromStore = true; - } + if ($fromStore !== false) { $storeParsedQuery['___from_store'] = $fromStore === true ? $this->_storeManager->getStore()->getCode() : $fromStore; } + $requestStringParts = explode('?', $requestString, 2); + $requestStringPath = $requestStringParts[0]; + if (isset($requestStringParts[1])) { + parse_str($requestStringParts[1], $requestString); + } else { + $requestString = []; + } + + $currentUrlQueryParams = array_merge($requestString, $storeParsedQuery); + $currentUrl = $storeParsedUrl['scheme'] . '://' . $storeParsedUrl['host'] . (isset($storeParsedUrl['port']) ? ':' . $storeParsedUrl['port'] : '') - . $storeParsedUrl['path']; - - //avoid query params duplication - if (!preg_match('/___store=(.*?)&___from_store=(.*?)/', $requestString)) { - $currentUrl .= $requestString; - } - - $currentUrl .= ($storeParsedQuery ? '?' . http_build_query($storeParsedQuery, '', '&') : ''); + . $storeParsedUrl['path'] + . $requestStringPath + . ($currentUrlQueryParams ? '?' . http_build_query($currentUrlQueryParams, '', '&') : ''); return $currentUrl; } diff --git a/dev/tests/integration/testsuite/Magento/Store/Model/StoreTest.php b/dev/tests/integration/testsuite/Magento/Store/Model/StoreTest.php index 67fe8d1dedea9..e62436460998f 100644 --- a/dev/tests/integration/testsuite/Magento/Store/Model/StoreTest.php +++ b/dev/tests/integration/testsuite/Magento/Store/Model/StoreTest.php @@ -274,7 +274,7 @@ public function testGetCurrentUrl() $this->model->load('admin'); $this->model->expects($this->any())->method('getUrl')->will($this->returnValue('http://localhost/index.php')); $this->assertStringEndsWith('default', $this->model->getCurrentUrl()); - $this->assertStringEndsWith('default', $this->model->getCurrentUrl(false)); + $this->assertStringEndsNotWith('default', $this->model->getCurrentUrl(false)); } /**