How to get all products?

Vote:
 

In the CMs i can use this bit of code to gett al lpages of a certain type:

var pageTypeId = contentTypeRepository
.Load()
.ID;

var criteriaCollection = new PropertyCriteriaCollection
{
new PropertyCriteria
{
Condition = CompareCondition.Equal,
Name = "PageTypeID",
Type = PropertyDataType.PageType,
Value = pageTypeId.ToString(),
Required = true
}
};

return pageCriteriaQueryService.FindPagesWithCriteria(
MetaDataRootType.PageLink,
criteriaCollection).Select(x => x as RoyaltySchemeType)
.ToReadOnlyList();

I want to be able to do the equivilant in commerce, so get all products that are of a certain type regardless of where they live int he tree... I'm guessing this is a simple one, how do I go about doign it?

#123239
Jun 29, 2015 18:26
Vote:
 

 

//this.Root = e commerce root
ContentLinks = this.contentLoader.GetDescendents(this.Root),
                    Languages = this.languageBranchRepository.ListEnabled()
                        .Select(x => x.Culture)

 

#123240
Jun 29, 2015 18:36
Vote:
 

Thanks for the code.  Our cataloug has somethign silly like 10,000 items in it, so this api call would take a while I guessing?  I will give it a test but prob need more somethign like CatalogEntrySearchCriteria although I have no idea how to use it  to filter on product types :(

#123241
Edited, Jun 29, 2015 18:38
Vote:
 
CatalogEntrySearchCriteria criteria = new CatalogEntrySearchCriteria();
criteria.SearchPhrase = "fanon";
SearchManager manager = new SearchManager(AppContext.Current.ApplicationName);
SearchResults results = manager.Search(criteria);

try if this still works

#123242
Jun 29, 2015 18:41
Vote:
 

To filter on content types, you can specify the ClassType of the CatalogEntrySearchCriteria - as Khan's answer - something like:

criteria.ClassType.Add("product"); //variation/bundle/...

If you want to filter down to the metaclass, use this:

                criteria.Add("_metaclass", new SimpleValue() { key = "_metaclass", value = <metaclass Name>});

Regards.

/Q

#123245
Jun 30, 2015 0:34
* 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.