How to get all products?

Member since: 2007

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

var pageTypeId = contentTypeRepository

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

return pageCriteriaQueryService.FindPagesWithCriteria(
criteriaCollection).Select(x => x as RoyaltySchemeType)

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
  • Member since: 2007


    //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
  • Member since: 2007

    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
  • Member since: 2007
    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
  • Member since: 2011

    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>});



    #123245 Jun 30, 2015 0:34