Wednesday, January 24, 2007

Pulling Out the Catalog Context

The Catalog Context is a very important part of the Catalog System of the Commerce Server. The catalog context is the only way through which can pull out catalogs,categories and work with them. One thing very smart in a commerce application is that the commerce context is defined at the time of creation of the commerce website. This means that as soon as we create a new commerce server website the commerce context is defined or initialized in the web.config of the application. So hence to call or initialize the catalog context we can directly use the web.config's commerce context. This can be done in the following manner :
return CommerceContext.Current.CatalogSystem;
So hence we see that instead of explicit catalog context call, we can directly initialize the catalog context. This may seem to be a very small thing, but on the contrary if your application is big enough, it will certainly boost up the speed of the application. This is due to the fact that if you explicitly call the catalog content using the siteagent i.e by doing:

//Create a CatalogSiteAgent to connect to the database.
CatalogSiteAgent catalogSiteAgent = new CatalogSiteAgent();
catalogSiteAgent.SiteName = "Give the appropiate sitename";

//Create the CatalogContext object.
CatalogContext catalogContext = CatalogContext.Create(catalogSiteAgent);
return catalogContext;

By doing this, you may get the same catalog context, however it may be initialized n number of times for n number of calls. Hence the first method is quite efficient and effective.

No comments: