CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Monday, September 11, 2006

ASP.NET and Commerce Server

Introduction

If you want to develop commerce server application, do remember setup vs.net first, then setup commerce server. After setup, you will find "Commerce Project" option in the New Project list.

The code below will give you a rough idea how to interact with commerce server.

1. Get categories from a Catalog

private void CategoryBind()

{

ProductCatalog ProdCtlg =CommerceContext.Current.CatalogSystem.GetCatalog("LevisJeans");

DataSet ds=new DataSet();

ds=ProdCtlg.GetRootCategories();

drpCategory.DataSource=ds.Tables[0].DefaultView;

drpCategory.DataTextField="CategoryName";

drpCategory.DataValueField="OrigCategoryName";

drpCategory.DataBind();

}

2. Bind products based on the category selected

private void DataBind()

{

ProductCatalog ProdCtlg =CommerceContext.Current.CatalogSystem.GetCatalog("LevisJeans");

Category Cg;

Cg=ProdCtlg.GetCategory(drpCategory.SelectedValue);

DataGrid4.DataSource=Cg.GetProducts();

DataGrid4.DataBind();

}

<img src="slcs/productlist.jpg">

 The below get list of products put into cart

private void DataBind()

{

TransactionContext txContext=TransactionContext.Current;

#if DEBUG

System.Console.WriteLine("HERE");

#endif

tot_qty=0;

tot_price=0;

DataGrid1.DataSource=txContext.CartOrderForm.LineItems;

DataGrid1.DataBind();

lblTot_Qty.Text=Convert.ToString(tot_qty);

lblTot_Price.Text=Convert.ToString(tot_price);

}

<img src="slcs/cart.jpg">

Below code is to delete one item

int d=Convert.ToInt16(deleted[j]);

txContext.CartOrderForm.LineItems.Remove(d)

 

Post a Comment