Skip to content

Commit 8b7c919

Browse files
Merge remote-tracking branch '38394/patch-6' into comps_78764_2205
2 parents f5140bc + abe49ac commit 8b7c919

File tree

2 files changed

+110
-1
lines changed
  • app/code/Magento/Catalog/Model/ResourceModel
  • dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel

2 files changed

+110
-1
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Url.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ protected function _getCategories($categoryIds, $storeId = null, $path = null)
412412
if (!is_array($categoryIds)) {
413413
$categoryIds = [$categoryIds];
414414
}
415-
$isActiveExpr = $connection->getCheckSql('c.value_id > 0', 'c.value', 'c.value');
415+
$isActiveExpr = $connection->getCheckSql('c.value_id IS NOT NULL', 'c.value', 'd.value');
416416
$select = $connection->select()->from(
417417
['main_table' => $this->getTable('catalog_category_entity')],
418418
[
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Model\ResourceModel;
9+
10+
use Magento\Catalog\Api\CategoryRepositoryInterface;
11+
use Magento\Catalog\Test\Fixture\Category as CategoryFixture;
12+
use Magento\Framework\Exception\CouldNotSaveException;
13+
use Magento\Framework\Exception\NoSuchEntityException;
14+
use Magento\Store\Model\StoreManagerInterface;
15+
use Magento\TestFramework\Fixture\DataFixture;
16+
use Magento\TestFramework\Fixture\DataFixtureStorage;
17+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
18+
use Magento\TestFramework\Fixture\DbIsolation;
19+
use Magento\TestFramework\Helper\Bootstrap;
20+
use PHPUnit\Framework\TestCase;
21+
22+
/**
23+
* Tests for the Catalog Url Resource Model.
24+
*/
25+
class UrlTest extends TestCase
26+
{
27+
/**
28+
* @var CategoryRepositoryInterface
29+
*/
30+
private CategoryRepositoryInterface $categoryRepository;
31+
32+
/**
33+
* @var DataFixtureStorage
34+
*/
35+
private DataFixtureStorage $fixtures;
36+
37+
/**
38+
* @var StoreManagerInterface
39+
*/
40+
private StoreManagerInterface $storeManager;
41+
42+
/**
43+
* @var Url
44+
*/
45+
private Url $urlResource;
46+
47+
protected function setUp(): void
48+
{
49+
$objectManager = Bootstrap::getObjectManager();
50+
$this->categoryRepository = $objectManager->create(CategoryRepositoryInterface::class);
51+
$this->fixtures = $objectManager->get(DataFixtureStorageManager::class)->getStorage();
52+
$this->storeManager = $objectManager->create(StoreManagerInterface::class);
53+
$this->urlResource = $objectManager->create(Url::class);
54+
}
55+
56+
/**
57+
* Test that scope is respected for the is_active flag.
58+
*
59+
* @return void
60+
* @throws NoSuchEntityException|CouldNotSaveException
61+
*/
62+
#[
63+
DbIsolation(true),
64+
DataFixture(CategoryFixture::class, [
65+
'name' => 'Enabled on default scope',
66+
'is_active' => '1',
67+
], 'c1'),
68+
DataFixture(CategoryFixture::class, [
69+
'name' => 'Disabled on default scope',
70+
'is_active' => '0',
71+
], 'c2'),
72+
DataFixture(CategoryFixture::class, [
73+
'name' => 'Enabled on default scope, disabled for store',
74+
'is_active' => '1',
75+
], 'c3'),
76+
DataFixture(CategoryFixture::class, [
77+
'name' => 'Disabled on default scope, enabled for store',
78+
'is_active' => '0',
79+
], 'c4'),
80+
]
81+
public function testIsActiveScope(): void
82+
{
83+
// Get Store ID
84+
$storeId = (int) $this->storeManager->getStore('default')->getId();
85+
86+
// Get Category IDs
87+
$categoryIds = [];
88+
foreach (['c1', 'c2', 'c3', 'c4'] as $fixtureName) {
89+
$categoryIds[$fixtureName] = (int) $this->fixtures->get($fixtureName)->getId();
90+
}
91+
92+
// Disable c3 for store
93+
$c3 = $this->categoryRepository->get($categoryIds['c3'], $storeId);
94+
$c3->setIsActive(false);
95+
$this->categoryRepository->save($c3);
96+
97+
// Enable c4 for store
98+
$c4 = $this->categoryRepository->get($categoryIds['c4'], $storeId);
99+
$c4->setIsActive(true);
100+
$this->categoryRepository->save($c4);
101+
102+
// Check categories
103+
$categories = $this->urlResource->getCategories($categoryIds, $storeId);
104+
$this->assertSame('1', $categories[$categoryIds['c1']]->getIsActive());
105+
$this->assertSame('0', $categories[$categoryIds['c2']]->getIsActive());
106+
$this->assertSame('0', $categories[$categoryIds['c3']]->getIsActive());
107+
$this->assertSame('1', $categories[$categoryIds['c4']]->getIsActive());
108+
}
109+
}

0 commit comments

Comments
 (0)