Skip to content

Commit b8f5c53

Browse files
committed
graphQl-527: Category Tree Contains null Leaves
1 parent 0e8428c commit b8f5c53

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

app/code/Magento/CatalogGraphQl/Model/Category/DepthCalculator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public function calculate(FieldNode $fieldNode) : int
2626
$depth = count($selections) ? 1 : 0;
2727
$childrenDepth = [0];
2828
foreach ($selections as $node) {
29-
if ($node->kind === 'InlineFragment') {
29+
if ($node->kind === 'InlineFragment'
30+
|| null !== $node->alias
31+
) {
3032
continue;
3133
}
3234

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\GraphQl\Catalog;
99

1010
use Magento\Catalog\Api\Data\CategoryInterface;
11+
use Magento\Catalog\Model\CategoryRepository;
1112
use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection;
1213
use Magento\Framework\DataObject;
1314
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
@@ -23,9 +24,15 @@ class CategoryTest extends GraphQlAbstract
2324
*/
2425
private $objectManager;
2526

27+
/**
28+
* @var CategoryRepository
29+
*/
30+
private $categoryRepository;
31+
2632
protected function setUp()
2733
{
2834
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
35+
$this->categoryRepository = $this->objectManager->get(CategoryRepository::class);
2936
}
3037

3138
/**
@@ -103,6 +110,42 @@ public function testCategoriesTree()
103110
);
104111
}
105112

113+
/**
114+
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
115+
*/
116+
public function testCategoriesTreeWithDisabledCategory()
117+
{
118+
$category = $this->categoryRepository->get(3);
119+
$category->setIsActive(false);
120+
$this->categoryRepository->save($category);
121+
122+
$rootCategoryId = 2;
123+
$query = <<<QUERY
124+
{
125+
category(id: {$rootCategoryId}) {
126+
id
127+
name
128+
level
129+
description
130+
children {
131+
id
132+
name
133+
productImagePreview: products(pageSize: 1) {
134+
items {
135+
id
136+
}
137+
}
138+
}
139+
}
140+
}
141+
QUERY;
142+
$response = $this->graphQlQuery($query);
143+
144+
$this->assertArrayHasKey('category', $response);
145+
$this->assertArrayHasKey('children', $response['category']);
146+
$this->assertSame(6, count($response['category']['children']));
147+
}
148+
106149
/**
107150
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
108151
*/

0 commit comments

Comments
 (0)