Try our conversational search powered by Generative AI!

Facets on the product category pages

Vote:
 

Hi, 

The requirement is to display products and variants inside a category where the results are paged and the user can filter results based on the facets he selects. 

I found this code to find the children of a catalog node but I think it is missing the facets 

//Get the currently configured content loader and reference converter from the service locator
var contentLoader = ServiceLocator.Current.GetInstance();
var referenceConverter = ServiceLocator.Current.GetInstance();
 
//Get the correct category id as it's represented in EPiServer Commerce
//In this example we arbitrarily use the integer 1
var nodeIdFromCommerce = 1;
 
//We use the content link builder to get the contentlink to our product
var productLink = referenceConverter.GetContentLink(nodeIdFromCommerce, CatalogContentType.CatalogNode, 0);
 
//Get the children using CMS API
var children = contentLoader.GetChildren(productLink);

The other option I am looking at is to use the Lucene search. It will give you entries and facets. The only problem I have with this model is that my catalog model requires a collection of VariationContents not entries. Should I change the model to require entries or is there some other  way of directly retrieving the Variant contents by the search provider along with facets? 

Another question I have is that with the VariantionContent object, I can access some of the basic information about variation but I don't see any way of retrieving the meta fields for this variantion.

Any help with these questions will be really appreciated. 

Thanks,

Syed

#88399
Jul 11, 2014 0:12
Vote:
 

Hi,

In this case using search providers (Lucene, or even better, Find) is the right approach. But it's only on SearchManager level, you can use this code:

SearchManager manager = new SearchManager(AppContext.Current.ApplicationName);
ISearchResults results = manager.Search(criteria);
int[] resultIndexes = results.GetKeyFieldValues();

resultIndexes is an array of CatalogEntryId which match your criteria. Now you can use ReferenceConverter to get content links, then load the contents.

Hope this helps.

Regards.

/Q

#88400
Jul 11, 2014 4:18
Vote:
 

Thanks Quan, 

The following code worked for me for converting one id. 

 var referenceConverter = ServiceLocator.Current.GetInstance();           
             ContentReference  content = referenceConverter.GetContentLink(resultIndexes[0],CatalogContentType.CatalogEntry,1 ).ToReferenceWithoutVersion();            
             VariationContent variant= (VariationContent) content.Get(); 

Is above the most effiecient way of doing it? 

Is there any method fo the ReferenceConverter that can take array of ids as input and return an array of content refferneces? 

Thanks,

Syed

#88424
Edited, Jul 11, 2014 18:01
Vote:
 

Yes, it is. The ReferenceConverter's methods (except for the one which takes code as parameter) work on memory, therefore they are extremely fast. Use a foreach and you can get content links in matter of millisecond :).

Regards.

/Q

#88430
Jul 12, 2014 16:12
Vote:
 

Hi Quan,

 VariationContent variant= (VariationContent) content.Get();

is taking a long time to load. E.g. showing 50 variants on the page will take a few seconds to load. Any better way to conver the content link into variationcontent?

Thanks,

Syed

#88614
Jul 19, 2014 0:09
Vote:
 

VariationContent variant= (VariationContent) content.Get();

You're using an extension method here. To load multiple contents at once, I would suggest to use IContentRepository.IEnumerable GetItems(IEnumerable contentLinks, ILanguageSelector selector) instead.

Regards.

/Q

#88620
Jul 21, 2014 6:52
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.