Skip to content

Calling getCurrentUrl on Store will wrongly add "___store" parameter #18941 #19135

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

Merged
merged 10 commits into from
Dec 19, 2018
Merged
4 changes: 4 additions & 0 deletions app/code/Magento/Store/Model/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,10 @@ public function getCurrentUrl($fromStore = true)

$storeUrl = $this->getUrl('', ['_secure' => $this->_storeManager->getStore()->isCurrentlySecure()]);

if ($this->_config->getValue(self::XML_PATH_STORE_IN_URL)) {
$storeUrl = preg_replace('/\/'.$this->getCode().'{1}/','',$storeUrl);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that URL is generated in Magento framework, not passed from outside, can you please reorganize the code to prevent adding store code to the URL instead of cutting it off after it is added.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method getUrl add parameters to url for specified scope, $url = $this->_url->setScope($this);
Is this right to change this on getUrl method?

}

if (!filter_var($storeUrl, FILTER_VALIDATE_URL)) {
return $storeUrl;
}
Expand Down
12 changes: 12 additions & 0 deletions dev/tests/integration/testsuite/Magento/Store/Model/StoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,24 @@ public function testIsCanDelete()
$this->assertFalse($this->model->isCanDelete());
}

/**
* @magentoDataFixture Magento/Store/_files/second_store.php
*/
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->model->load('fixture_second_store');

\Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class)
->setValue(Store::XML_PATH_STORE_IN_URL, true, ScopeInterface::SCOPE_STORE);

$this->assertEquals('http://localhost/index.php?___store=fixture_second_store&___from_store=default', $this->model->getCurrentUrl(true));
$this->assertEquals('http://localhost/index.php?___store=fixture_second_store', $this->model->getCurrentUrl(false));
}

/**
Expand Down