Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,22 @@ private function getCountFromCategoryTableBulk(
[]
)
->where('ce.entity_id IN (?)', $categoryIds);

$connection->query(
$connection->insertFromSelect(
$selectDescendants,
$tempTableName,
['category_id', 'descendant_id']
)
);
foreach ($categoryIds as $catId) {
$connection->insert(
$tempTableName,
[
'category_id' => $catId,
'descendant_id' => $catId
]
);
}
$select = $connection->select()
->from(
['t' => $tempTableName],
Expand Down
30 changes: 30 additions & 0 deletions app/code/Magento/Catalog/Test/Unit/Helper/CategoryTestHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Copyright 2025 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

namespace Magento\Catalog\Test\Unit\Helper;

use Magento\Catalog\Model\Category;

/**
* Test helper class for Catalog Category with custom methods
*
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
*/
class CategoryTestHelper extends Category
{

/**
* Get is anchor
*
* @return bool
*/
public function getIsAnchor(): bool
{
return $this->getData('is_anchor');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Magento\Catalog\Test\Unit\Model\ResourceModel\Category;

use Magento\Catalog\Model\Category;
use Magento\Catalog\Test\Unit\Helper\CategoryTestHelper;
use Magento\Framework\Data\Collection\EntityFactory;
use Magento\Store\Model\Store;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -229,11 +230,7 @@ public function testLoadProductCountCallsBulkMethodForLargeCategoryCount()
$items = [];
$categoryIds = [];
for ($i = 1; $i <= $categoryCount; $i++) {
$category = $this->getMockBuilder(Category::class)
->addMethods(['getIsAnchor'])
->onlyMethods(['getId', 'setProductCount'])
->disableOriginalConstructor()
->getMock();
$category = $this->createMock(CategoryTestHelper::class);
$category->method('getId')->willReturn($i);
$category->method('getIsAnchor')->willReturn(true);
$category->expects($this->once())->method('setProductCount')->with(5);
Expand Down Expand Up @@ -265,6 +262,26 @@ public function testLoadProductCountCallsBulkMethodForLargeCategoryCount()
$this->connection->method('select')->willReturn($this->select);
$this->connection->method('insertFromSelect')->willReturn('INSERT QUERY');
$this->connection->method('query')->with('INSERT QUERY')->willReturnSelf();
$withs = [];
foreach ($categoryIds as $categoryId) {
$withs[] = [
'category_id' => $categoryId,
'descendant_id' => $categoryId
];
}
$callIndex = 0;
$this->connection
->expects($this->exactly(count($categoryIds)))
->method('insert')
->with(
$this->stringContains('temp_category_descendants_'),
$this->callback(function($args) use (&$callIndex, $withs) {
$expected = $withs[$callIndex];
$valid = $args === $expected;
$callIndex++;
return $valid;
})
);
$this->select->method('from')->willReturnSelf();
$this->select->method('joinLeft')->willReturnSelf();
$this->select->method('join')->willReturnSelf();
Expand Down