2

Now I receive children number using this code:

$currentCategory = $this->getCurrentCategory();
$childrenCount = $currentCategory->getChildrenCount();

But it counts both enabled and disabled children.

Do you know method that counts only enabled children, or I have to filter them in block?

1 Answer 1

3

You can use like,

$currentCategory = $this->getCurrentCategory();
$childCategory=$currentCategory->getChildrenCategories()->addIsActiveFilter();
echo count($childCategory);
2
  • Just in case you can also call count as method $childCategory->count();!
    – electroid
    Jul 21, 2018 at 10:42
  • If you only care about the number of categories, you should better use $childCategory->getSize() to not load the full collection.
    – Simon
    Sep 26 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.