Skip to content

Commit

Permalink
#11211 Fix Store View switcher, undo integration test changes and ref…
Browse files Browse the repository at this point in the history
…actory
  • Loading branch information
thiagolima-bm committed Oct 21, 2017
1 parent beccd7d commit 84729b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 14 additions & 11 deletions app/code/Magento/Store/Model/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down

0 comments on commit 84729b5

Please sign in to comment.