Skip to content

Commit f9acb65

Browse files
committed
Added a separate resolver for returning category products count
1 parent 9186f4a commit f9acb65

File tree

3 files changed

+2
-3
lines changed

3 files changed

+2
-3
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public function hydrateCategory(Category $category, $basicFieldsOnly = false) :
5252
$categoryData = $category->getData();
5353
} else {
5454
$categoryData = $this->dataObjectProcessor->buildOutputDataArray($category, CategoryInterface::class);
55-
$categoryData['product_count'] = $category->getProductCount();
5655
}
5756
$categoryData['id'] = $category->getId();
5857
$categoryData['children'] = [];

app/code/Magento/CatalogGraphQl/Model/Resolver/Category/Products.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function resolve(
6565
'eq' => $value['id']
6666
]
6767
];
68-
$searchCriteria = $this->searchCriteriaBuilder->build($field->getName(), $args);
68+
$searchCriteria = $this->searchCriteriaBuilder->build($field->getName(), $args);
6969
$searchCriteria->setCurrentPage($args['currentPage']);
7070
$searchCriteria->setPageSize($args['pageSize']);
7171
$searchResult = $this->filterQuery->getResult($searchCriteria, $info);

app/code/Magento/CatalogGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ interface CategoryInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model
379379
level: Int @doc(description: "Indicates the depth of the category within the tree")
380380
created_at: String @doc(description: "Timestamp indicating when the category was created")
381381
updated_at: String @doc(description: "Timestamp indicating when the category was updated")
382-
product_count: Int @doc(description: "The number of products in the category")
382+
product_count: Int @doc(description: "The number of products in the category") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\ProductsCount")
383383
default_sort_by: String @doc(description: "The attribute to use for sorting")
384384
products(
385385
pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. This attribute is optional."),

0 commit comments

Comments
 (0)