Expand my Community achievements bar.

Is it possible to use Out of the box Category Retriever from CIF

Avatar

Level 9

Hi Team,

 

I am aware of creating the custom category retriver class in my project.

import com.adobe.cq.commerce.core.components.models.retriever.AbstractCategoriesRetriever;
 
class ABCCategoryRetriever extends AbstractCategoriesRetriever
{  write necessary methods here .... }
 
But, now I wanted to use the out of the box cif category retriever as it is.Then, call the utility methods
CategoryFilterInput, CategoryTreeQueryDefinition to set the filters, query.  So, Is there any category retriever present in  CIF project, that I can use directly?
 
I am aware of these classes.

com.adobe.cq.commerce.core.components.internal.models.v1.categorylist.CategoriesRetriever
com.adobe.cq.commerce.core.components.models.productlist.CategoryRetriever

com.adobe.cq.commerce.core.components.models.retriever.AbstractCategoryRetriever
com.adobe.cq.commerce.core.components.models.retriever.AbstractCategoriesRetriever

com.adobe.cq.commerce.core.components.internal.models.v1.breadcrumb.BreadcrumbRetriever

 

But, I cannot call these classes direclty from my sling model class.

cc @AmitVishwakarma   @AMANATH_ULLAH  @sarav_prakash  @arunpatidar  @mk_aem21 

 

Thanks

 

 

3 Replies

Avatar

Level 7

Yes, you can use the out-of-the-box CIF category retriever. The relevant class is CategoriesRetriever.

To use it:

1. Inject the CategoriesRetriever into your Sling model using @reference.
2. Use CategoryFilterInput to set filters and CategoryTreeQueryDefinition to define your query.
3. Call categoriesRetriever.getCategories(queryDefinition) to retrieve the categories.

Here's a quick example:

@reference
private CategoriesRetriever categoriesRetriever;

public void getCategories() {
    CategoryFilterInput filterInput = new CategoryFilterInput();
    CategoryTreeQueryDefinition query = new CategoryTreeQueryDefinition(filterInput);
    List<CategoryModel> categories = categoriesRetriever.getCategories(query);
}

This way, you don’t need a custom retriever class.

Avatar

Level 9

Hi @AmitVishwakarma 

 

Are you sure about this solution? I mean have you used in your project like this?

Why I am asking is: "com.adobe.cq.commerce.core.components.internal.models.v1.categorylist.CategoriesRetriever"   As this suggests, this is internal one. So, is it possible to use as

@Reference
private CategoriesRetriever categoriesRetriever;

 

Avatar

Level 9

Hi @AmitVishwakarma 

 

I am getting this error, while building the project

Bundle abc.core:1.0.0-SNAPSHOT is importing package(s)
com.adobe.cq.commerce.core.components.internal.models.v1.categorylist in start level 20 but no bundle is exporting these for that start level. (com.abc:abcd.all:1.0.0-SNAPSHOT)