This document provides an overview of the Catalog Data Sources features.
All classes referred to here are available in the Mediachase.Commerce.Catalog.DataSources namespace.
Key classes and files
- CatalogIndexSearchDataSource - represents a catalog search data source for data-bound controls.
- CatalogItemsDataSource.cs - represents a catalog items data source for data-bound controls.
- CatalogSearchDataSource.cs - represents catalog search data source for data-bound controls
Overview
Below is an overview of the Catalog Data Sources API structure.
How it works
Example: creating a CatalogIndexSearchDataSource
C#
private CatalogIndexSearchDataSource CreateCatalogIndexSearchDataSource()
{
SearchFilterHelper sfHelper = SearchFilterHelper.Current;
string keywords = Request.QueryString["search"];
SearchSort sortObject = CatalogEntrySearchCriteria.DefaultSortOrder
CatalogEntrySearchCriteria criteria = sfHelper.CreateSearchCriteria(keywords, sortObject);
int startIndex = SomeListView.StartRowIndex;
int recordsToRetrieve = pageSize;
int count = 0;
CatalogEntryResponseGroup responseGroup = new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo);
bool cacheResults = true;
TimeSpan cacheTimeout = new TimeSpan(0, 0, 30);
CatalogIndexSearchDataSource dataSource = null;
if (criteria.CatalogNames.Count != 0)
{
Entries entries = sfHelper.SearchEntries(criteria, startIndex, recordsToRetrieve, out count, responseGroup, cacheResults, cacheTimeout);
dataSource = new CatalogIndexSearchDataSource();
dataSource.TotalResults = count;
dataSource.CatalogEntries = entries;
}
return dataSource;
}
Once the CatalogIndexSearchDataSource object is created, you can bind it to an ASP.NET server control that supports data binding, such as the ListView control. When this is done, you will have access to a collection of catalog entry results.
Example: accessing a catalog entry results collection
C#
SomeListView.DataSource = CatalogIndexSearchDataSource
CatalogIndexSearchDataSource.CatalogEntries
CatalogIndexSearchDataSource.CatalogEntries.Entry
Do you find this information helpful? Please log in to provide feedback.