From 3eef2afc98729f364ea8b79d033543c87f53d15c Mon Sep 17 00:00:00 2001 From: Iurii Ivashchenko Date: Tue, 5 Feb 2019 15:55:46 +0200 Subject: [PATCH 1/2] MAGETWO-97898: [Magento Cloud] Store switcher URL redirects to the same store --- .../Store/Model/StoreResolver/Website.php | 2 +- .../Store/Model/StoreResolver/WebsiteTest.php | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 dev/tests/integration/testsuite/Magento/Store/Model/StoreResolver/WebsiteTest.php diff --git a/app/code/Magento/Store/Model/StoreResolver/Website.php b/app/code/Magento/Store/Model/StoreResolver/Website.php index 29f85716fea29..2a8b30a007ad9 100644 --- a/app/code/Magento/Store/Model/StoreResolver/Website.php +++ b/app/code/Magento/Store/Model/StoreResolver/Website.php @@ -45,7 +45,7 @@ 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()) { + if (!$scopeCode || ($store->isActive() && $store->getWebsiteId() === $website->getId())) { $stores[] = $store->getId(); } } diff --git a/dev/tests/integration/testsuite/Magento/Store/Model/StoreResolver/WebsiteTest.php b/dev/tests/integration/testsuite/Magento/Store/Model/StoreResolver/WebsiteTest.php new file mode 100644 index 0000000000000..cc10b91a031cc --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Store/Model/StoreResolver/WebsiteTest.php @@ -0,0 +1,62 @@ +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'); + } +} From 8634afc57fe063d368ce5f1c4d98e97f5536903a Mon Sep 17 00:00:00 2001 From: Iurii Ivashchenko Date: Wed, 6 Feb 2019 15:43:17 +0200 Subject: [PATCH 2/2] MAGETWO-97898: [Magento Cloud] Store switcher URL redirects to the same store --- app/code/Magento/Store/Model/StoreResolver/Website.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Store/Model/StoreResolver/Website.php b/app/code/Magento/Store/Model/StoreResolver/Website.php index 2a8b30a007ad9..d4bb990307f1e 100644 --- a/app/code/Magento/Store/Model/StoreResolver/Website.php +++ b/app/code/Magento/Store/Model/StoreResolver/Website.php @@ -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 (!$scopeCode || ($store->isActive() && $store->getWebsiteId() === $website->getId())) { - $stores[] = $store->getId(); + if ($store->isActive()) { + if (!$scopeCode || ($store->getWebsiteId() === $website->getId())) { + $stores[] = $store->getId(); + } } } return $stores;