cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to hide categories with no products?

Former Member
1,068

We are not using WCMS in our website. We get the top navigation menu from a custom category heirarchy which we have made. So in a case, where a category has no products tagged to it, we shouldn't display it.

I guess we could check if the category has products getProducts() and then if its subcategories have products. but is there a better way to do this?. Is there any existing service to get all products associated to a category?

View Entire Topic
9999999
Participant
0 Likes

I used this and it worked well

.filter(category -> !productService.getProductsForCategory(category).isEmpty())