Skip to content

Commit

Permalink
Added a separate resolver for returning category products count
Browse files Browse the repository at this point in the history
  • Loading branch information
rogyar committed Nov 8, 2018
1 parent 9186f4a commit f9acb65
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public function hydrateCategory(Category $category, $basicFieldsOnly = false) :
$categoryData = $category->getData();
} else {
$categoryData = $this->dataObjectProcessor->buildOutputDataArray($category, CategoryInterface::class);
$categoryData['product_count'] = $category->getProductCount();
}
$categoryData['id'] = $category->getId();
$categoryData['children'] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function resolve(
'eq' => $value['id']
]
];
$searchCriteria = $this->searchCriteriaBuilder->build($field->getName(), $args);
$searchCriteria = $this->searchCriteriaBuilder->build($field->getName(), $args);
$searchCriteria->setCurrentPage($args['currentPage']);
$searchCriteria->setPageSize($args['pageSize']);
$searchResult = $this->filterQuery->getResult($searchCriteria, $info);
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/CatalogGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ interface CategoryInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model
level: Int @doc(description: "Indicates the depth of the category within the tree")
created_at: String @doc(description: "Timestamp indicating when the category was created")
updated_at: String @doc(description: "Timestamp indicating when the category was updated")
product_count: Int @doc(description: "The number of products in the category")
product_count: Int @doc(description: "The number of products in the category") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\ProductsCount")
default_sort_by: String @doc(description: "The attribute to use for sorting")
products(
pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. This attribute is optional."),
Expand Down

0 comments on commit f9acb65

Please sign in to comment.