on 2017 Oct 24 10:53 AM
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?
Request clarification before answering.
The service you want is ProductService. There are methods for checking if a category has products as well as returning all products for a given category. Based on your example I think productService.containsProductsForCategory(aCategoryModel) should do the trick.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I used this and it worked well
.filter(category -> !productService.getProductsForCategory(category).isEmpty())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Directly we cannot implement this. because this categories information comes from solr. also when categories retried it will not check if there are any active products or not. Once user select the category then it will query the database to identify the active products from the category. Directly we cannot hide this empty category.
If you really want to implement then you have to customize your code to hide such categories.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.