Skip to content

Commit 84729b5

Browse files
committed
#11211 Fix Store View switcher, undo integration test changes and refactory
1 parent beccd7d commit 84729b5

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

app/code/Magento/Store/Model/Store.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,26 +1166,29 @@ public function getCurrentUrl($fromStore = true)
11661166
if (!$this->isUseStoreInUrl()) {
11671167
$storeParsedQuery['___store'] = $this->getCode();
11681168
}
1169-
if ($this->getCode() !== $this->_storeManager->getStore()->getCode()) {
1170-
$fromStore = true;
1171-
}
1169+
11721170
if ($fromStore !== false) {
11731171
$storeParsedQuery['___from_store'] = $fromStore ===
11741172
true ? $this->_storeManager->getStore()->getCode() : $fromStore;
11751173
}
11761174

1175+
$requestStringParts = explode('?', $requestString, 2);
1176+
$requestStringPath = $requestStringParts[0];
1177+
if (isset($requestStringParts[1])) {
1178+
parse_str($requestStringParts[1], $requestString);
1179+
} else {
1180+
$requestString = [];
1181+
}
1182+
1183+
$currentUrlQueryParams = array_merge($requestString, $storeParsedQuery);
1184+
11771185
$currentUrl = $storeParsedUrl['scheme']
11781186
. '://'
11791187
. $storeParsedUrl['host']
11801188
. (isset($storeParsedUrl['port']) ? ':' . $storeParsedUrl['port'] : '')
1181-
. $storeParsedUrl['path'];
1182-
1183-
//avoid query params duplication
1184-
if (!preg_match('/___store=(.*?)&___from_store=(.*?)/', $requestString)) {
1185-
$currentUrl .= $requestString;
1186-
}
1187-
1188-
$currentUrl .= ($storeParsedQuery ? '?' . http_build_query($storeParsedQuery, '', '&') : '');
1189+
. $storeParsedUrl['path']
1190+
. $requestStringPath
1191+
. ($currentUrlQueryParams ? '?' . http_build_query($currentUrlQueryParams, '', '&') : '');
11891192

11901193
return $currentUrl;
11911194
}

dev/tests/integration/testsuite/Magento/Store/Model/StoreTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public function testGetCurrentUrl()
274274
$this->model->load('admin');
275275
$this->model->expects($this->any())->method('getUrl')->will($this->returnValue('http://localhost/index.php'));
276276
$this->assertStringEndsWith('default', $this->model->getCurrentUrl());
277-
$this->assertStringEndsWith('default', $this->model->getCurrentUrl(false));
277+
$this->assertStringEndsNotWith('default', $this->model->getCurrentUrl(false));
278278
}
279279

280280
/**

0 commit comments

Comments
 (0)