CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeff Lynch [MVP]

Everything E-Commerce!

Commerce Server 2007: Development Tip #7 - Using the CatalogItemsDataSet

I'm going to repost this series of "development tips" related to Commerce Server 2007 to help other folks get started with their development work. All of these "tips" come directly from what I've learned (the hard way) over the past eight months and are intended to save you time and effort. All code samples are now based upon the RTM version and have been tested in our production environment.

One of the best "features" of the revamped Catalog subsystem is the use of the strongly-typed CatalogItemsDataSet to return category, product and inventory data. This really simplifies your site code and offers a great deal of flexibility as shown in the code samples below.

public CatalogItemsDataSet GetRootProducts(string CatalogName)
{
    return CommerceContext.Current.CatalogSystem.GetCatalog(CatalogName).GetRootCategory().ChildProducts.DataSet;
}
 
 
public CatalogItemsDataSet GetCategoryProducts(string CatalogName, string CategoryName)
{
    return CommerceContext.Current.CatalogSystem.GetCatalog(CatalogName).GetCategory(CategoryName).ChildProducts.DataSet;
}
 
 
public CatalogItemsDataSet GetRootCategories(string CatalogName)
{
    return CommerceContext.Current.CatalogSystem.GetCatalog(CatalogName).GetRootCategory().ChildCategories.DataSet;
}
 
 
public CatalogItemsDataSet GetSubCategories(string CatalogName, string CategoryName)
{
    return CommerceContext.Current.CatalogSystem.GetCatalog(CatalogName).GetCategory(CategoryName).ChildCategories.DataSet;
}
 
 
public CatalogItemsDataSet SearchForProducts(string CatalogName, string SearchPhrase)
{        
    CatalogSearch catalogSearch = CommerceContext.Current.CatalogSystem.GetCatalogSearch();
    catalogSearch.CatalogNames = CatalogName; 
    catalogSearch.SearchOptions.ClassTypes = CatalogClassTypes.ProductClass;
    catalogSearch.FreeTextSearchPhrase = SearchPhrase; 
    return catalogSearch.Search();
} 
 
As you can see, the CatalogItemsDataSet is pretty versatile and is easily bound to any ASP.NET databound control.
 
 
Technorati Tags: 

Published Jul 12 2006, 10:05 PM by jlynch
Filed under:

Comments

rseroter said:

It's "comically prolific" in a good way ;)
# May 12, 2006 11:02 AM

jlynch said:

Richard,

I just hope I don't have to revise all these posts after RC!
# May 12, 2006 12:59 PM

Jeff Lynch [MVP] said:

What do I do if the StarterSite doesn't fit my scenario?

# January 4, 2007 8:28 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

This Blog

Syndication

News