Loading...
Area: Optimizely Commerce
Applies to versions: 10 and higher
Other versions:

Filtering catalog content

Recommended reading 

This topic provides examples of filtering catalog content in a Commerce solution using the Optimizely Search & Navigation (formerly Find) - Commerce integration (EPiServer.Find.Commerce). The examples use predefined filters to narrow results on catalog content.

Markets

Filtering content on current market:

var results = SearchClient.Instance.Search<VariationContent>()
.FilterOnCurrentMarket().GetContentResult();

Filtering content on market:

var result = SearchClient.Instance.Search<VariationContent>()
    .Filter(x => x.AvailableMarkets().MatchContained(v => v.Value, "market"));
Pricing

Filtering content with currency:

var result = SearchClient.Instance.Search<VariationContent>()
    .Filter(x => x.DefaultPrice().UnitPrice.Currency.Match(currency));

Filtering content with price less than:

var result = SearchClient.Instance.Search<VariationContent>()
    .Filter(x => x.DefaultPrice().UnitPrice.LessThan(2));
Filtering content with price greater than:
var result = SearchClient.Instance.Search<VariationContent>()
    .Filter(x => x.DefaultPrice().UnitPrice.GreaterThan(2));

Filtering content with price in range:

var result = SearchClient.Instance.Search<VariationContent>()
    .Filter(x => x.DefaultPrice().UnitPrice.InRange(2, 4))

Bundles

Filtering bundle entries:

var result = SearchClient.Instance.Search<BundleContent>()
    .Filter(x => x.BundleEntries().MatchContained(c => c.ID, contentReference.ID));

Filtering parent bundles:

var result = SearchClient.Instance.Search<EntryContentBase>() 
.Filter(x => x.ParentBundles().MatchContained(c => c.ID, contentReference.ID));

Packages

Filtering package entries:

var result = SearchClient.Instance.Search<PackageContent>()
    .Filter(x => x.PackageEntries().MatchContained(c => c.ID, contentReference.ID));

Filtering parent packages:

var result = SearchClient.Instance.Search<EntryContentBase>()
    .Filter(x => x.ParentPackages().MatchContained(c => c.ID, contentReference.ID));

Node relations

Filtering parent node relations:

var result = SearchClient.Instance.Search<BundleContent>()
    .Filter(x => x.ParentNodeRelations().MatchContained(c => c.ID, contentReference.ID));

Filtering child node relations:

var result = SearchClient.Instance.Search<BundleContent>()
    .Filter(x => x.ChildNodeRelations().MatchContained(c => c.ID, contentReference.ID));
Do you find this information helpful? Please log in to provide feedback.

Last updated: Jun 08, 2020

Recommended reading