Manmit Walia's Blog

Sharing solutions one post at a time
Query Commerce Server Catalog

So today one of my tasks was to query Commerce Server catalog system and update a sql database table for an off site custom web application. The concept was to be able to search on products based on a division id (basically a group). For those who have never queried Commerce Server before it is pretty easy once you understand the underlying object model.

There many ways to query the catalog in Commerce Server

  1. Using the old Sql Odbc Connection method to connect to the product catalog database
  2. Using the out of the box Commerce Server web services [recommend this for simple data retrieval concept]
  3. Using Commerce context and the object model to query the system.

Due to our complexity of the catalog (ex. multiple base catalog and virtual catalogs), I decided to query the system via option 3. This not only gives me the flexibility to the entire object model but the ability to scale my application easily based on catalog updates.

The first step is to create a agent which is basically your connectivity to the catalog system. An agent can be either a catalog site agent, profile agent or even marketing agent. Once the agent is created I know can do a Catalog Search which underlying is a LIKE query. In this scenario, I just wanted to get all products from the particular catalog thus I am not refining my query.

// Create a CatalogSiteAgent to connect to the database. 
CatalogSiteAgent  catalogSiteAgent = new  CatalogSiteAgent ();
catalogSiteAgent.SiteName = SiteName;
CatalogContext  catalogContext = CatalogContext .Create(catalogSiteAgent);
 
// Create the CatalogContext object. 
ProductCatalog  productCatalog = (ProductCatalog )catalogContext.GetCatalog(CatalogName, "en-US" );
CatalogSearch  catalogSearch = catalogContext.GetCatalogSearch();
catalogSearch.SearchOptions = new  CatalogSearchOptions ();
catalogSearch.SearchOptions.ClassTypes = CatalogClassTypes .ProductClass | CatalogClassTypes .ProductFamilyClass | CatalogClassTypes .ProductVariantsForFamilyClass;
catalogSearch.SearchOptions.PropertiesToReturn = "ProductId,DisplayName,Description" ;
catalogSearch.SearchOptions.SortDescending = true ;
catalogSearch.SearchOptions.SortProperty = "ProductId,DisplayName" ; 
 

By declaring my catalog search query, I can now retrieve the results and bind them into a Catalog Item DataSet.

CatalogItemsDataSet  searchResults = catalogSearch.Search(out  totalRecords);
 
 

From here you can use basic ADO or even Linq to query granular based on business needs. Feedbacks are most welcome.

Posted: Jun 28 2010, 10:45 PM by saeapu | with no comments
Filed under: , ,
My First SharePoint 2010 Upgrade Part 1

So I have been reading a lot around lately that the upgrade process from SharePoint 2007 to 2010 is very smooth. Well last night I decided to give it a shot. I decided to install SharePoint 2010 on my windows 7 machine, a great step by step can be found here. (NOTE: This link is around Beta 2 but the general steps are the same.)

After my installation of SharePoint 2010, I decided to take a back up copy of the content database. Which took a while to transfer over (whew!!! 5 GB of data). After long hours of wait (damn dsl network) I went ahead and created a blank site in SharePoint 2010. Once the site was created which was pretty easy to do (love the new wizard feature in SharePoint 2010), I deleted the content database. Well enough for now, I will continue this tomorrow…Got some deadlines to finish up :)

About Me

Welcome to my blog! Please take a seat and enjoy a complimentary drink. My name is Manmit Walia and I'm currently working as a Enterprise Architect at Newell Rubbermaid in Atlanta, Georgia. This basically involves working with an agile team of developers and testers, making sure that whatever the customer asked us to build doesn't crash and burn into a smoldering mess. This blog consists mainly of posts about architecture, technology and development processes, but has been known to go off on random tangents from time to time. Should this occur, please remain seated and stay calm until it blows over. Comments to posts are welcomed, particularly if they are intelligent, controversial or insane. 

More Posts