Thursday, September 13, 2007

Setting Up Profile System In Commerce Server 2007



Well, i am gonna explain how to set up the profile system on the commerce server API.


Well to start of open the Commerce Manager. The Commerce Manager is the whole sum of all the services of Commerce. Now the Commerce Profile API can be explained by the above image.
If you look at the above image, it shows the entire Commerce Profile Heirarchy.
Now lets get started on our main task. To Set up Profile System, go to the Commerce Site node. Click on the option to Add a resource in the site. Browse to the default CSharp.pup when asked and in that select the profile item. Now as soon as you do that your Profile Db and schema are generated. The Profile Schema is visible inside the Commerce Manager itself.
To access the profiles, Go to the Global Resource node. In that you will find the Product Catalog. In paralled to Product Catalog is the site terms.
Site Terms are the properties with multiple value. These can be referred as properties which can have multiple values. For example we can have a site term called year which have all the months of the year.
The Second Node "Product Catalog" is the one which carries that two important things "Profile Definition" and "Data Source".
The DataSource has properties mapped directly to the DB, whereas Profile Definitions are the actual entities which carry the properties in which values are given in the user specific end.
Concluding the post, this system of all the systems is most user friendly and very easy to use.

Profile System

Well one of the intresting topic in Commerce is the Profile System. I believe that you know of a asp.net Membership scenerio. Well in Blogs a UserProfile if logged in is stored in the CommerceContext.Current.UserProfile
Now, in this blog I will explain the process of registration.

Firstly we provide a UserId. In my case i am using a asp.net User registration Wizard
// Set new user id. CommerceContext.Current.UserID = ((Guid)Membership.GetUser(UserRegWizard.UserName).ProviderUserKey).ToString();


Then we set the Commerce Profile :
commerceProfile.Profile currUserProfile = objUpmProfileProvider.GetCommerceProfile("GeneralInfo.email_address", TbxUserEmail.Text.Trim(), "UserObject");

Commerce has inbuilt Properties, you can make new properties using the Commerce Manager.

I will explain this in detail in another blog.


So Now we can set various properties of the commerce like
currUserProfile["GeneralInfo.first_name"].Value = userFirstName.Text.Trim();
After Setting the Properties to store it we do.
currUserProfile.Update();
Hence we just created a new user.
Hope the post is helpfull.

Wednesday, January 24, 2007

Catalog Search Over Explicit Search

In commerce server, the catalog search has been known to be the most easiest and flexible way to pull out effective needy data from the catalog system. However, this may be not true in some cases. In a catalog search , we are not taking into consideration that by catalog search we allow the commerce to search for each and every product within the given condition. This consumes more of time and effort. So hence a explicit search is always preferred over the catalog search.

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.

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.

Monday, September 18, 2006

The Catalog Context

Now here is some actual hands on experience with the commerce server environment…
Well in my last blog, i commented on the commerce server. There is lot of actual coding you can go and see on the msdn help on the commerce server but here on my blog I’ll try and explain those which I think is more usable in what I call a programmatic environment. Now to start off, as I told before the hierarchy goes like the catalog has various categories which has various products.
Note: Now there also are entities called the virtual catalogs and the sub categories which I’ll be discussing at a later point of time probably in my next blog

Everything in Commerce Server 2007 is both programmatic and both in design view, however as a developer I feel that at every point of time there are things that need to be changed in the normal code so as to achieve the desired result. Now trust me, no where in an organization a normal scenario is reached because a software developer is known for designing codes.

Well, firstly I go into
Understanding Catalog Context and the fundamentals of catalogs
How to read a Catalog


Now to Deal with the Catalogs in the Catalog System we have a IDE known as the Catalog Manager. It is a graphical user interface to deal with the catalog and related definitions. Now you must remember that when I am dealing with catalog,category and products, I suppose that the appropriate definitions have been already made as explained in my earlier post. It is done through the Catalog and Inventory Schema Manager. It’s simple to make the definitions, it having a good user interface.

Now the Catalog Context is a entity above catalogs or rather I should say for accessing control to deal with a catalog, you have to use a catalog context object.
On the whole,The Catalog Context object provides the functionality to manage your catalogs. It can be created in one of two modes. These two modes are different in the sense of their declaration.

It can be in local mode, where the code accesses the Commerce Server objects and the database directly and does not use a Web service. Here it uses what is called as the catalogsiteagent. The CatalogSiteAgent class contains configuration for a connection directly to a Commerce Server site's catalog database. So here in the catalogsite agent only by defining the sitename we can actually pull out the whole of catalog context.

Now one of my personal view regarding sitename is to declare sitename in the GlobalConstants.cs file. This is a special feature of the .net 2.0. We had a global.asax in .net1.1 where we used to define global variables, likewise in .net 2.0 we have a class file called Global Constants where if we define a variable we can access this variable anywhere within the solution.
e.g defining
public const string SITENAME = "SumitSite";
in the GlobalConstants.cs file we can use this SITENAME anywhere within the solution.

So by this way of local mode we can get the catalog context.
public static CatalogContext CreateCatalogContextFromSiteAgent()
{
// Create a CatalogSiteAgent to connect to the database.
CatalogSiteAgent catalogSiteAgent = new CatalogSiteAgent();
catalogSiteAgent.SiteName = "StarterSite";

// Create the CatalogContext object.
CatalogContext catalogContext = CatalogContext.Create(catalogSiteAgent);
return catalogContext;
}
Alternatively, it can be in agent mode, where calls to the catalog system are made through the Web service with the help of an agent. Although this method is not used that common because here we inherit a webservice called the CatalogServiceAgent where we have to pass the URL of the service as a parameter.



Now reading a catalog is a very important thing in the catalog system. When we read a catalog, we actually call the inbuilt function of the catalog context called the Get Catalogs. This returns all the catalogs. Similarly we can get the root categories and so on.

private static CatalogsDataSet GetCatalogs(CatalogContext context)
{
return context.GetCatalogs();
}

Now this is the Catalog Part to get the catalogs, there is actually a lot on using the catalog, retrieving a category, product and lots more which will be there in my upcoming blogs. Also check out my other blog http://sumitatlas.blogspot.com, which I’ll be starting today itself.

Sunday, September 10, 2006

The Catalog System- A Brief Overview

Today, I am going write something about the catalog system in the commerce server 2007. The Catalog system not only is a very important feature of the Commerce Server 2007 but is also beneficial for large enterprise sites. Well it goes like this; the catalog system introduces the concept of putting all data in a well organized manner without actual logical interaction with the database.
This means that without interacting with the SQL server you can actually build the whole website.

A more elaboration on the topic will be that a catalog is nothing but a data entity at a large level. It is subdivided into categories and products.

CATALOG à CATEGORY à PRODUCT

This means that a catalog can be divided into several categories and each category can have various products. This is the main fundamental of the catalog system in the commerce server 2007.

Take an example of a large shopping mall site. The mall would certainly have a book store. So say we created a catalog for books.
In the Commerce Server Catalog Manager we go and make a new Catalog called Books. So the books can be said to be a catalog. The internet books, java books, novels, classics are the category of books whereas a particular book as in Unleashed .net 2.0 is a product. So here we see how the whole thing is so much sub-divided as to make things simpler. Now the question is what are the attributes and on what parameters each of these are made. So, here comes the role of the schema. For one minute just leave the example and lets study how the schema of an entity is handled in the commerce server.

XML data is considered to be favorite among some people as they say it is more structural data. Creating a xsd structure of the data is a very popular way of dealing with XML. Similarly the commerce server 2007 introduces the catalog and inventory schema manager. This manager gives the power to populate various structures or schema for various definitions of the catalog System. It is mainly divided into three parts. Let’s start from the smallest entity definition to a bigger one.

Property Definitions: The property definition gives the power to define properties. These are the Attributes of a Product in the catalog System. The Property is the smallest entity that is there is the catalog system. The property is a attribute of a product. For example for a particular book we have title and author, all these are the properties of a product.
Product Definitions: The Product Definitions is what the schema for a particular product is. This means that when we start to make a product then the catalog system asks for a product definition. This is basically the attributes of a product.

Note: Please don’t ge6t confused between the two definitions. The property definition is the general definition for all the attributes in the entire catalog system whereas the product definition is restricted to the schema for a product. It means that the product definition is mainly for a specific product whereas a property is a different universal thing. Moreover on creating a product definition we get a a property list to choose properties to make a schema for a product definition.

Category Definition: A category definition also involves choosing from a list of properties; On the contrary here we are selecting properties for the attributes of a specific category.

This was an abstract of what the Catalog System is in the Commerce Server 2007.
The Commerce Server introduces many such systems which are very beneficial for making good ERP sites. My next post will give you an idea of the coding involved in Catalog System.

The Start has begun

hello , everyone , I am Sumit Sethi, a Software Developer. More or less knowledge is a thing which is always a gr8 thing to share.. I work for a firm and everyday search sites and blogs for code snippets and info. Likewise, i now know it is a boon for us developers. So from today, ill be writing on topics i'm currently on touch with. Mainly on Commerce Server 2007, VS2005,.net2.0 and ATLAS. So be in touch and give comments if you feel like
Sumit