Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private MultipleProductSearchResults GetMultipleProductSearchResults(BaseItem dataSource,
CommerceSearchOptions productSearchOptions)
{
Assert.ArgumentNotNull(productSearchOptions, "productSearchOptions");
MultilistField searchesField = dataSource.Fields[Templates.ProductSearch.Fields.NamedSearches.ToString()];
var searches = searchesField.GetItems();
var productsSearchResults = new List<SearchResults>();
foreach (var search in searches)
{
if (TemplateManager.GetTemplate(search).GetBaseTemplates().FirstOrDefault(t => t.ID == Templates.NamedSearch.ID) != null)
{
var productsSearchResult = _catalogManager.GetProductSearchResults(search, productSearchOptions);
if (productsSearchResult != null)
{
productsSearchResult.NamedSearchItem = search;
productsSearchResult.DisplayName = search[Templates.NamedSearch.Fields.Title.ToString()];
productsSearchResults.Add(productsSearchResult);
}
}
else if (TemplateManager.GetTemplate(search).GetBaseTemplates().FirstOrDefault(t => t.ID == Templates.SelectedProducts.ID) != null)
{
var itemCount = 0;
var staticSearchList = new SearchResults
{
DisplayName = search[Templates.SelectedProducts.Fields.Title.ToString()],
NamedSearchItem = search
};
MultilistField productListField = search.Fields[Templates.SelectedProducts.Fields.ProductList.ToString()];
var productList = productListField.GetItems();
foreach (var productItem in productList)
{
var catalogItemtype = productItem.ItemType();
if (catalogItemtype == StorefrontConstants.ItemTypes.Category || catalogItemtype == StorefrontConstants.ItemTypes.Product)
{
staticSearchList.SearchResultItems.Add(productItem);
itemCount++;
}
}
staticSearchList.TotalItemCount = itemCount;
staticSearchList.TotalPageCount = itemCount;
productsSearchResults.Add(staticSearchList);
}
}
return new MultipleProductSearchResults(productsSearchResults);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.