count Product underneath a category

mojtaba kavand asked on May 30, 2014 02:15

Hi there,

is there any predefine macro method or something to count products underneath top level categories

e.g. CatA-->CatB-->CatC

I want to retrieve all products underneath catA which is including all products underneath catB and catC

Correct Answer

Josef Dvorak answered on June 19, 2014 09:24

Hi Mojtaba

I see. Unfortunately there is no such macro in Kentico. The only two solution in this case is to develop a Custom Macro Method, which will recursively add up values of CategoryCount column for all of the category children.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Josef Dvorak answered on June 6, 2014 08:33 (last edited on December 10, 2019 02:30)

Hi Mojtaba

There is no native method which could do this. While you can return number of all documents in the sub-tree, like this:

{% CurrentDocument.AllChildren.Count |(identity)GlobalAdministrator%}

The AllChildren object does not support filtering, so categories would be counted in the result.

The only solution in this case is to create and register a Custom Macro Method, and calculate number of child nodes which represent a product using the API.

Examples of how to retrieve a DataSet of documents based on a where condition can be found in the API Examples module, which is part of a Kentico installation

0 votesVote for this answer Mark as a Correct answer

mojtaba kavand answered on June 9, 2014 18:06

Hi Josef AllChildren object just work for document tree nodes not category nodes ...

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.