Monday, October 30, 2006

Pulling Out Data from Catalog System

Data Retrieval in Commerce Server 2007


Seach Clause Factory : In search clause, we usually find a product using the Catalog Name, the Category Name, and the Search Clause. To do this we usually do the following :

CatalogItemsDataSet catItemDs = new CatalogItemsDataSet();
CatalogSearch catalogSearch = CommerceContext.Current.CatalogSystem.GetCatalogSearch();
CatalogSearch.CatalogNames = "TheCatalogName";
CatalogSearch.CategoryName = "TheCategoryName";
CatalogSearch.SearchOptions.ClassTypes = CatalogClassTypes.ProductClass;

// set the search creitera
CatalogSearch.SqlWhereClause = "Item1 = '" +value + "'";
// Here we specify the condition for which the search has to be done.
// returns CatalogItemsDataSet
catItemDs = catalogSearch.Search();
//to get the desired properties

Here we get the desired properties of the products.



The Second and the most simple way of getting the product out the catalog System is through specifying the ProductId, and the Catalog Name. We do this in the following manner :

Product p = cc.GetProduct(CatalogName, ProductId);
After this we can get the value of the properties of the products

Thursday, October 19, 2006

Business Logic

Each and every Control requires business logic which in programming language is called a Business Object. This is done in order to maintain the balance between the business layer and the data layer so as to efficiently use the data in the custom controls.

Working : Whenever we create a custom control ( a .cs file), we never call the database or the commerce server API in the control itself. Instead we follow a hierarchy.

There are three files in the working of a control which all exists in the App_Code folder of the Solution.
1. The Data Provider: This is the actual code file which deals directly with the commerce server API or the database indirectly. The main function of the data provider is to get the data from the commerce server API and give this data to the business logic or the business object.
2. The Business Object: This File plays a very important role as not only it takes in the required data from the data provider, but on the other hand gives this data to the custom control.
3. The Custom Control: The most important is the custom control which defines the look and feel of the control utilizing the data given by the business object

A good elaboration would be :
----> Business Object ( BO.cs)
Class BO
{
Private string m_name;
Public string name
{ get{ return m_name;} set{ m_name = value;}
}


----> Data Provider ( DP.cs)
Class DP
{
Public void dataprovider ( string CatalogName, string ProductId)
{
// cc = commerce context
Product P = cc.GetProduct( CatalogName, ProductId);
BO BusinessItem = new BO();
BusinessItem.name = p.Information.CatalogItems[0].Table.Rows[0]["Name"].ToString();
Return BusinessItem;
}
}


----> Custom Control ( CC.cs)
Class CC
{
BO BItem = new BO;
DP Dprovider = new DP;
BItem = DP.dataprovider ( CatalogName, Product Id);
Label L1 = new Label();
L1.Text = BItem.name;

}

So Hence we see, how we use a Data Provider and Business Object to be used in the custom control. This approach makes the logic flow very good.