Skip to content

Commit

Permalink
Merge pull request #3735 from magento-mpi/port-97898
Browse files Browse the repository at this point in the history
Fixed issues:
- [MAGETWO-97898](https://jira.corp.magento.com/browse/MAGETWO-97898) [Magento Cloud] Store switcher URL redirects to the same store
  • Loading branch information
igrybkov authored Feb 12, 2019
2 parents 199eff2 + 5775719 commit 18f226f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/code/Magento/Store/Model/StoreResolver/Website.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ public function getAllowedStoreIds($scopeCode)
$stores = [];
$website = $scopeCode ? $this->websiteRepository->get($scopeCode) : $this->websiteRepository->getDefault();
foreach ($this->storeRepository->getList() as $store) {
if ($store->isActive() && $store->getWebsiteId() == $website->getId()) {
$stores[] = $store->getId();
if ($store->isActive()) {
if (!$scopeCode || ($store->getWebsiteId() === $website->getId())) {
$stores[] = $store->getId();
}
}
}
return $stores;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Store\Model\StoreResolver;

use Magento\TestFramework\Helper\Bootstrap;

class WebsiteTest extends \PHPUnit\Framework\TestCase
{
/**
* @var Website
*/
private $reader;

protected function setUp()
{
$this->reader = Bootstrap::getObjectManager()->create(Website::class);
}

/**
* Tests retrieving of stores id by passed scope.
*
* @param string|null $scopeCode website code
* @param int $storesCount
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
* @dataProvider scopeDataProvider
*/
public function testGetAllowedStoreIds($scopeCode, $storesCount)
{
$this->assertCount($storesCount, $this->reader->getAllowedStoreIds($scopeCode));
}

/**
* Provides scopes and corresponding count of resolved stores.
*
* @return array
*/
public function scopeDataProvider(): array
{
return [
[null, 4],
['test', 2]
];
}

/**
* Tests retrieving of stores id by passing incorrect scope.
*
* @expectedException \Magento\Framework\Exception\NoSuchEntityException
* @expectedExceptionMessage The website with code not_exists that was requested wasn't found.
*/
public function testIncorrectScope()
{
$this->reader->getAllowedStoreIds('not_exists');
}
}

0 comments on commit 18f226f

Please sign in to comment.