Skip to content

Commit d452a36

Browse files
committed
Query category for disabled catalog with products returns the products count
1 parent f3d7a0d commit d452a36

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7979
}
8080

8181
$result = $this->extractDataFromCategoryTree->execute($categoriesTree);
82-
return current($result);
82+
83+
$category = current($result);
84+
if ($category['is_active'] == false) {
85+
throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist'));
86+
}
87+
88+
return $category;
8389
}
8490
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,25 @@ public function testGetCategoryById()
122122
self::assertEquals(13, $response['category']['id']);
123123
}
124124

125+
/**
126+
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
127+
* @expectedException \Exception
128+
* @expectedExceptionMessage Category doesn't exist
129+
*/
130+
public function testGetDisabledCategory()
131+
{
132+
$categoryId = 8;
133+
$query = <<<QUERY
134+
{
135+
category(id: {$categoryId}) {
136+
id
137+
name
138+
}
139+
}
140+
QUERY;
141+
$this->graphQlQuery($query);
142+
}
143+
125144
public function testNonExistentCategoryWithProductCount()
126145
{
127146
$query = <<<QUERY

0 commit comments

Comments
 (0)