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)); } /**