diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Url.php b/app/code/Magento/Catalog/Model/ResourceModel/Url.php index 81763be25a2b0..ba07cf0ed2ef2 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Url.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Url.php @@ -412,7 +412,7 @@ protected function _getCategories($categoryIds, $storeId = null, $path = null) if (!is_array($categoryIds)) { $categoryIds = [$categoryIds]; } - $isActiveExpr = $connection->getCheckSql('c.value_id > 0', 'c.value', 'c.value'); + $isActiveExpr = $connection->getCheckSql('c.value_id IS NOT NULL', 'c.value', 'd.value'); $select = $connection->select()->from( ['main_table' => $this->getTable('catalog_category_entity')], [ diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/UrlTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/UrlTest.php new file mode 100644 index 0000000000000..624d4101ac843 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/UrlTest.php @@ -0,0 +1,109 @@ +categoryRepository = $objectManager->create(CategoryRepositoryInterface::class); + $this->fixtures = $objectManager->get(DataFixtureStorageManager::class)->getStorage(); + $this->storeManager = $objectManager->create(StoreManagerInterface::class); + $this->urlResource = $objectManager->create(Url::class); + } + + /** + * Test that scope is respected for the is_active flag. + * + * @return void + * @throws NoSuchEntityException|CouldNotSaveException + */ + #[ + DbIsolation(true), + DataFixture(CategoryFixture::class, [ + 'name' => 'Enabled on default scope', + 'is_active' => '1', + ], 'c1'), + DataFixture(CategoryFixture::class, [ + 'name' => 'Disabled on default scope', + 'is_active' => '0', + ], 'c2'), + DataFixture(CategoryFixture::class, [ + 'name' => 'Enabled on default scope, disabled for store', + 'is_active' => '1', + ], 'c3'), + DataFixture(CategoryFixture::class, [ + 'name' => 'Disabled on default scope, enabled for store', + 'is_active' => '0', + ], 'c4'), + ] + public function testIsActiveScope(): void + { + // Get Store ID + $storeId = (int) $this->storeManager->getStore('default')->getId(); + + // Get Category IDs + $categoryIds = []; + foreach (['c1', 'c2', 'c3', 'c4'] as $fixtureName) { + $categoryIds[$fixtureName] = (int) $this->fixtures->get($fixtureName)->getId(); + } + + // Disable c3 for store + $c3 = $this->categoryRepository->get($categoryIds['c3'], $storeId); + $c3->setIsActive(false); + $this->categoryRepository->save($c3); + + // Enable c4 for store + $c4 = $this->categoryRepository->get($categoryIds['c4'], $storeId); + $c4->setIsActive(true); + $this->categoryRepository->save($c4); + + // Check categories + $categories = $this->urlResource->getCategories($categoryIds, $storeId); + $this->assertSame('1', $categories[$categoryIds['c1']]->getIsActive()); + $this->assertSame('0', $categories[$categoryIds['c2']]->getIsActive()); + $this->assertSame('0', $categories[$categoryIds['c3']]->getIsActive()); + $this->assertSame('1', $categories[$categoryIds['c4']]->getIsActive()); + } +}