Skip to content

Commit 6c6047d

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

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

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

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

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

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
use Magento\CatalogGraphQl\Model\Category\Hydrator;
1111
use Magento\Catalog\Api\Data\CategoryInterface;
12+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
13+
use Magento\Catalog\Model\Category;
1214

1315
/**
1416
* Extract data from category tree
@@ -51,6 +53,9 @@ public function execute(\Iterator $iterator): array
5153
while ($iterator->valid()) {
5254
/** @var CategoryInterface $category */
5355
$category = $iterator->current();
56+
if ($category->getIsActive() == false && $category->getId() != Category::TREE_ROOT_ID) {
57+
throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist'));
58+
}
5459
$iterator->next();
5560
$pathElements = explode("/", $category->getPath());
5661
if (empty($tree)) {

0 commit comments

Comments
 (0)