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
2 changes: 1 addition & 1 deletion app/code/Magento/Store/Url/Plugin/RouteParamsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function beforeSetRouteParams(
$storeCode
);

if ($useStoreInUrl && !$this->storeManager->hasSingleStore()) {
if (!$useStoreInUrl && !$this->storeManager->hasSingleStore()) {
$this->queryParamsResolver->setQueryParam('___store', $storeCode);
}
}
Expand Down
57 changes: 57 additions & 0 deletions dev/tests/integration/testsuite/Magento/Store/Model/StoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

namespace Magento\Store\Model;

use Magento\Catalog\Model\ProductRepository;
use Magento\Framework\App\Bootstrap;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\UrlInterface;
use Magento\Store\Api\StoreRepositoryInterface;
use Zend\Stdlib\Parameters;

/**
Expand Down Expand Up @@ -267,12 +270,66 @@ public function testIsCanDelete()
$this->assertFalse($this->model->isCanDelete());
}

/**
* @magentoDataFixture Magento/Store/_files/core_second_third_fixturestore.php
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
* @magentoDbIsolation disabled
*/
public function testGetCurrentUrl()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class)
->setValue('web/url/use_store', true, ScopeInterface::SCOPE_STORE, 'secondstore');

$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));

/** @var \Magento\Store\Model\Store $secondStore */
$secondStore = $objectManager->get(StoreRepositoryInterface::class)->get('secondstore');

/** @var \Magento\Catalog\Model\ProductRepository $productRepository */
$productRepository = $objectManager->create(ProductRepository::class);
$product = $productRepository->get('simple');
$product->setStoreId($secondStore->getId());
$url = $product->getUrlInStore();

$this->assertEquals('http://localhost/index.php/secondstore/catalog/product/view/id/1/s/simple-product/', $url);
$this->assertEquals('http://localhost/index.php/secondstore/?___from_store=default', $secondStore->getCurrentUrl());
$this->assertEquals('http://localhost/index.php/secondstore/', $secondStore->getCurrentUrl(false));
}

/**
* @magentoDataFixture Magento/Store/_files/second_store.php
* @magentoDataFixture Magento/Catalog/_files/category_product.php
* @magentoDbIsolation disabled
*/
public function testGetCurrentUrlWithUseStoreInUrlFalse()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$objectManager->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class)
->setValue('web/url/use_store', false, ScopeInterface::SCOPE_STORE, 'default');

/** @var \Magento\Store\Model\Store $secondStore */
$secondStore = $objectManager->get(StoreRepositoryInterface::class)->get('fixture_second_store');

/** @var \Magento\Catalog\Model\ProductRepository $productRepository */
$productRepository = $objectManager->create(ProductRepository::class);
$product = $productRepository->get('simple333');

$product->setStoreId($secondStore->getId());
$url = $product->getUrlInStore();

/** @var \Magento\Catalog\Model\CategoryRepository $categoryRepository */
$categoryRepository = $objectManager->get(\Magento\Catalog\Model\CategoryRepository::class);
$category = $categoryRepository->get(333,$secondStore->getStoreId());

$this->assertEquals('http://localhost/index.php/catalog/category/view/s/category-1/id/333/',$category->getUrl());
$this->assertEquals('http://localhost/index.php/catalog/product/view/id/333/s/simple-product-three/?___store=fixture_second_store', $url);
$this->assertEquals('http://localhost/index.php/?___store=fixture_second_store&___from_store=default', $secondStore->getCurrentUrl());
$this->assertEquals('http://localhost/index.php/?___store=fixture_second_store', $secondStore->getCurrentUrl(false));

}

/**
Expand Down