3
E-Commerce using Commerce Server 2009 Commerce Server 2009 is a Microsoft pro- duct for building E-Commerce systems, using .NET based web services and an abstract business layer, known as the Commerce Server Foundation. The first release of this product was in the year 1996, known as Site Server. The last release of Site Server was in 1998. In 2000 when they released it they renamed it to Commerce Server. The current version (2009) was released last March. The SharePoint Commerce Services are responsible for the integration between SharePoint and Commerce Server. The platform is also a fully Service Orientated (SOA) enabled plat- form including BizTalk adapters. Advantages of Commerce Server 2009 will be noticed after running the SharePoint Commerce Services wizard. Users have the ability to use some SharePoint Web Parts and the Default Site (Image 1). These Web Parts vary from a Shopping basket Web Part to a “my Account” Web Part. A lot of these Web Parts are customizable by XSLT. Also shipped is the CommerceSharePointExtensibilityKit which contains the sources of these Web Parts and User Controls, which could be very useful for customizations. Web DEVELOPING WIDELY USABLE E- COMMERCE SOLUTIONS USING SHAREPOINT At the time of writing, the Netherlands has more than 20,000 online stores, a number which is continually expanding. Since SharePoint has become more widely deployed as an Internet solution, a requirement to have a SharePoint based e-Commerce-solution is now available. Previously the only option was to build a custom SharePoint solution, but now Microsoft Commerce Server 2009 can also be used for building a SharePoint based e-Commerce solution. The SharePoint Default Site is a complete sample site inside Sha- rePoint, using the Commerce Server Features. It’s possible to build your own E-commerce-solution in only a few steps, by defi- ning your own catalogue and connecting it to the Default Site. The available tools (Image 2), which connect using Web Services, are very helpful for tasks like defining your catalogue. By using the “Catalogue and Inventory Schema Manager” tool it is possible to make schema definitions for categories and products. Once de- fined you can then setup the properties for products and catego- ries within the catalogue. After this step a catalogue can be built and filled using the “Catalogue Manager” (Image 3). Nick Boumans Original Article: Dutch .NET magazine | september 2009

2009 9 Dutch Net Magazine Commerce Server By Nick Boumans Uk

Embed Size (px)

Citation preview

Page 1: 2009 9 Dutch Net Magazine Commerce Server By Nick Boumans Uk

E-Commerce using Commerce Server 2009

Commerce Server 2009 is a Microsoft pro-duct for building E-Commerce systems, using .NET based web services and an abstract business layer, known as the Commerce Server Foundation. The first release of this product was in the year 1996, known as Site Server. The last release of Site Server was in 1998. In 2000 when they released it they renamed it to Commerce Server. The current version (2009) was released last March. The SharePoint Commerce Services are responsible for the integration between SharePoint and Commerce Server. The platform is also a fully Service Orientated (SOA) enabled plat-form including BizTalk adapters.

Advantages of Commerce Server 2009will be noticed after running the SharePoint Commerce Services wizard. Users have the ability to use some SharePoint Web Parts and the Default Site (Image 1). These Web Parts vary from a Shopping basket Web Part to a “my Account” Web Part. A lot of these Web Parts are customizable by XSLT. Also shipped is the CommerceSharePointExtensibilityKit which contains the sources of these Web Parts and User Controls, which could be very useful for customizations.

Web

Developing wiDely usable e-commerce solutions using sharepoint

At the time of writing, the Netherlands has more than 20,000 online stores, a number which is continually expanding. Since SharePoint has become more widely deployed as an Internet solution, a requirement to have a SharePoint based e-Commerce-solution is now available. Previously the only option was to build a custom SharePoint solution, but now Microsoft Commerce Server 2009 can also be used for building a SharePoint based e-Commerce solution.

The SharePoint Default Site is a complete sample site inside Sha-rePoint, using the Commerce Server Features. It’s possible to build your own E-commerce-solution in only a few steps, by defi-ning your own catalogue and connecting it to the Default Site. The available tools (Image 2), which connect using Web Services, are very helpful for tasks like defining your catalogue. By using the “Catalogue and Inventory Schema Manager” tool it is possible to make schema definitions for categories and products. Once de-fined you can then setup the properties for products and catego-ries within the catalogue. After this step a catalogue can be built and filled using the “Catalogue Manager” (Image 3).

Nick Boumans

Original Article: Dutch .NET magazine | september 2009

Page 2: 2009 9 Dutch Net Magazine Commerce Server By Nick Boumans Uk

Original Article: Dutch .NET magazine | september 2009

Customizing the Commerce Server SharePoint Site is possible by customizing the master page and CSS. A lot of Web Parts are using a template which uses XSL. These templates could be found in the Document Library “Commerce Server Templates”. So it is also possible to put your custom templates into this libra-ry for use in the Web Parts. Using this method the most com-mon customizations could be made. You can think about the order of the columns in the Shopping Basket Web Part.

Development using the Commerce Server API makes it possible, by using .NET code, to customize e.g. the Default Site. By refer-ring some dll’s in your Visual Studio Project it will be possible to use these API’s. Commonly used dll’s are: Microsoft.CommerceServer.Runtime.dll

Microsoft.CommerceServer.Catalog.dll

Microsoft.Commerce.Portal.Common.dll

These dll’s could be found in the Web Part Extensibility Kit (CommerceSharePointExtensibilityKit). To make these dll’s avai-lable, you have to build the sample project from the Web Part Ex-tensibility Kit at the first time, after signing it with your own strong name key. The first step of development is the “Commerce Context”-class which could be found in the CommerceServer.Runtime.dll. This class makes it possible to manage catalogues. For the best performance you only have to create one instance of this object and reuse it during the lifetime of the application.

Development using the catalogue is one of the most common de-velopment questions. In practice this will result in requirements as: a Web Part inside SharePoint to show or manage products and categories. Beside the fact that this is possible using the Com-merce Server Tools or a Silverlight Web Part available from the Microsoft Site, in most situations this solution doesn’t meet the requirements of the customer.

Adding a product to the catalogue could be seen as a “Hello World”-development example for Commerce Server. As I menti-oned earlier in this article, the first step is getting access to the Commerce Context and using this context for modifying the cata-logue. In Code sample 1 you can see how it’s possible to add a product to the catalogue. The last code line is may be the most important one since changes will not be saved by forgetting the item.Save() procedure.// You have to add a reference to the Microsoft.CommerceServer.Ca-

talog.dll //(CommerceSharePointExtensibilityKit) and the

// Microsoft.CommerceServer.Runtime.dll

BaseCatalog baseCatalog = (BaseCatalog)CommerceContext.Current.Ca-

talogSystem.CatalogContext.GetCatalog(“Adventure Works Catalog”);

Product item = baseCatalog.CreateProduct(“Tents”, “Iglo”, 30m,

“Tents”);

item.DisplayName = “Iglo”;

item[“Description”] = “3mm Tent”;

item.Save();

CODESAMPLE 1: ADDING A PRODUCT TO A CATEGORY IN A CATALOGUE

A Category definition describes the category in the catalogue. This is a collection of properties which specify how information has to be saved into a category. At the creation of a category defi-nition, this definition will be added to the catalogue schema.To build a category definition:

1. Create a category definition by using the CreateDefintion me-thod of the CatalogContext object.2. Create properties using the AddProperty method of the Cata-logDefinition object.3. CatalogDefinition.Save() to save the definition.

Code sample 2 creates a catalogue definition “Movie Category” by creating a CatalogDefinition object.public static void CreateCategoryDefinition(CatalogContext con-

text)

{

// Create a category definition for categories in a DVD cata-

log.

CatalogDefinition categoryDefinition = context.

CreateDefinition(“Movie Category”, CatalogDefinitionType.Category-

Definition);

categoryDefinition.Description = “Categories for DVDs”;

// Create a description property for this category.

CatalogProperty description = context.

CreateProperty(“Description”, CatalogDataType.String, 500);

// Add the property to the category definition.

categoryDefinition.AddProperty(description.Name, Definition-

PropertyType.NormalProperty);

// Save the definition.

categoryDefinition.Save();

}

CODESAMPLE 2: BUILDING A CATEGORY DEFINITION

Adding and deleting categories is the logical next step after crea-ting a category definition. The catalogue has two methods: Crea-teCategory and DeleteCategory. By adding a category you have to define a category definition. Code sample 3 and 4 shows how a category could be added and deleted by using the Catalog API. After deleting a category the method “PurgeDeletedItems” is res-ponsible for actual deleting items of the Catalog Database.

No time for installing and configuring? You can download the Microsoft Commerce Server 2009 VPC and start today!

Page 3: 2009 9 Dutch Net Magazine Commerce Server By Nick Boumans Uk

BaseCatalog baseCatalog = (BaseCatalog)CommerceContext.Current.Ca-

talogSystem.CatalogContext.GetCatalog(“Movie Catalog”);

// Add a category

Category category = baseCatalog.CreateCategory(“MovieCategory”,

“Adventure”);

category.DisplayName = “Adventure”;

category[“Description”] = “Adventure Movies”;

category.Save();

CODESAMPLE 3: ADDING A CATEGORY

ProductCatalog productCatalog = (ProductCatalog)CommerceContext.

Current.CatalogSystem.CatalogContext.GetCatalog(“Movie Catalog”);

// Delete the category

productCatalog.DeleteCategory(“MovieCategory”);

// Remove the deleted items from the catalog database

productCatalog.PurgeDeletedItems();

CODESAMPLE 4: DELETING A CATEGORY

Newbie using Commerce Server 2009?Maybe as a SharePoint developer you have not yet dived into Commerce Server; however, it is really worth a try. If you don’t want to spend any time on the installation and configuration be-fore you can exercise, as you can download a Microsoft Com-merce Server VPC from the Microsoft Connect site.

LinksBlog Nick Boumans: http://www.sharepointdevelopment.nl

Commerce Server 2009 VPC: https://connect.microsoft.com/Downloads/Download-

Details.aspx?SiteID=643&DownloadID=16926

MSDN Commerce Server 2009 Forum: http://social.msdn.microsoft.com/Forums/

en-US/commserver2009/threads

Inline property editor webpart: http://www.microsoft.com/downloads/details.

aspx?FamilyID=fce87672-90cf-4ead-b100-6bbc24d96f66&displaylang=en

Nick Boumans, is SharePoint specialist and Microsoft Certified Trainer in the Nether-

lands.

Blog: http://www.SharePointDevelopment.nl.

Original Article: Dutch .NET magazine | september 2009