Skip to content

Commit d41c407

Browse files
committed
Fixed non existant category with products issue
1 parent 0502433 commit d41c407

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7272

7373
$rootCategoryId = $this->getCategoryId($args);
7474
$categoriesTree = $this->categoryTree->getTree($info, $rootCategoryId);
75-
if (!empty($categoriesTree)) {
75+
if (!empty($categoriesTree) && ($categoriesTree->count() > 0)) {
7676
$result = $this->extractDataFromCategoryTree->execute($categoriesTree);
7777
return current($result);
7878
} else {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,21 @@ public function testCategoriesTree()
112112
);
113113
}
114114

115+
public function testNonExistentCategoryWithProductCount()
116+
{
117+
$query = <<<QUERY
118+
{
119+
category(id: 99) {
120+
product_count
121+
}
122+
}
123+
QUERY;
124+
125+
$response = $this->graphQlQuery($query);
126+
$expectedResponse = ['category' => null];
127+
$this->assertEquals($expectedResponse, $response);
128+
}
129+
115130
/**
116131
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
117132
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)

0 commit comments

Comments
 (0)