E-Commerce: Customizing and Extending the Commerce Starter Kit...

This series of articles is going to examine some of the issues around building a traditional B2C shopping cart e-commerce site using ASP.NET and SQL Server.


By: Chris Sully Date: December 15, 2004

1: Overview and the Commerce Starter Kit

Introduction

This series of articles is going to examine some of the issues around building a traditional B2C shopping cart e-commerce site using ASP.NET (VB.NET) and SQLServer. Some of the key functional areas are therefore:

We'll be looking at these areas, though not necessarily in this order or exclusively so, in this series! The plan is to keep the series open and to investigate any programming issues that arise along the way.

These articles shall be driven by a real world project I'm involved with currently with my company CW.net (www.cymru-web.net), which I'll describe briefly shortly after we look at why we might want to develop a bespoke solution and why we don't have to start completely from scratch.

Bespoke vs Off the Shelf

Has the following question already sprung to the mind of the reader - 'why are you developing a bespoke solution when there are off the shelf .NET e-commerce solutions out there already?' This would surely provide a more featureful solution that met the project requirements at a lower total cost. The main reason I'm not is that I can answer 'no' to this question. There is no guarantee that this would be the case. The product catalogue requirements in this instance are quite complex and so is some of the accompanying business logic. Thus I would need to purchase a solution which included the source code so I could tailor the application to my needs. Access to the source code costs more. Further there is the time investment required to get a good understanding of how the product is put together. So, yes ... no doubt more functionality would be available to my client ... but would it do exactly what my client required of it for less cost than a bespoke solution in a situation where my client is not particularly interested in all the extra functionality. Probably not.

Further, as a developer looking out for the best interests of my client I looked around for suitable .NET based off the shelf packages. They were surprisingly few and far between. Further I wasn't entirely convinced by either their architecture or suitability for the chosen hosting platform. Finally, the one I as interested in, a product called Storefront, did not offer a trial version so it could not be easily evaluated for suitability. I would normally have walked away at this point as generally I would say that this is not acceptable practice – nowadays one would expect to be able to trial such software. In this case however I took advantage of their 'we'll give your money back if not entirely satisfied within one month policy' and gave the product a reasonably thorough review. Suffice to say it was severely lacking in several areas so was returned. We did (eventually) receive our money back by the way! In summary, I cannot recommend StoreFront and my peers would seem to largely agree. The other .NET products we have since been recommended would have been prohibitively expensive in the context of this particular project. However, if you have personal experience of particularly products you views are welcome.

Where do we start?

We shall start from the position that I actually found myself in - we have our product catalogue and a web interface that displays these products to the world. Next step in the customer process is to allow browsers of the site to place products in their shopping basket. Somebody must have come up with a shopping cart solution before in .NET. Yes, Microsoft have ...

At the Microsoft ASP.NET site ( http://www.asp.net/Default.aspx?tabindex=9&tabid=47) there are a variety of 'starter kits' for download as well as other 'source projects' available at the site. The kits are, as of the time of writing:

These are five sample ASP.NET applications that provide code to accomplish common Web development tasks. Each sample is complete and documented so that you can use the code to 'kickstart your ASP.NET development projects today'.

This is exactly what we're going to do. We're going to use the Commerce starter to kickstart the development of our e-commerce site. As it happens it is only a start as the solution only goes so far. So first we'll have a look at the implementation, drawing out areas of importance to this particular project.

Note that if you visit www.ASP.net you'll see that there is also a commerce application (IBuyStore) available as a source project that seems to be remarkably similar to the commerce starter kit. What's the difference? Very little as far as I can tell. The starter kit seems to be a more recent endeavour so perhaps just a later version of the source project. Version 1.0 has been updated to support Windows 2003/ .NET 1.1.

The Commerce Starter Kit Overview

The Commerce Starter Kit demonstrates an ecommerce storefront application complete with shopping cart, product catalog, and a web service to submit orders.

The features of the kit, as per the ASP.NET site, are:

Product Catalog

Instant Order Web Service

Other features

Technologies and Design Approaches Demonstrated:

Note that the source code is available in both VS.NET/ code-behind and non VS.NET implementations and in C#, J# and VB.NET. I'll be using the VS.NET VB.NET version.

I've emboldened above the areas we'll be focussing on. You'll also notice that there are several areas mentioned in the introduction that are not covered by the starter kit. After all, it is a starter kit and we'll need to finish off our project on our own. Microsoft can't do all the work for us!

I'll briefly return to our example application domain for this series of articles before an initial consideration of the application architecture of the starter kit which we shall adopt and extend for this application.

Lockers online anyone?

Back to our example site. We're currently developing an e-commerce site for a manufacturer and distributor of lockers and related equipment.

Phase I of their project required a catalogue driven site to display their wares on their web site. This could be considered to be an e-commerce site in itself as it is facilitating Garran selling their products. However e-commerce in the context of this article series means accepting real-time payments.

This is the key requirement of phase II of the project, with the necessary supporting infrastructure also required. The first necessary step was extending the representative power of the product catalogue so it could identify products down to the productID level. This is our starting position.

Note that I had already discarded the generic catalogue facility provided by the e-commerce starter kit as too simplistic for the project requirements. You may well need to do the same.

Commerce Starter Kit Application Architecture

Traditional best practice is to separate your web application into several logical layers for several reasons including scalability (as you can implement these logical layers on distinct physical layers) and re-usability. As a minimum these layers would normally be:

USL – user services layer
BLL – business logic layer
DAL – data access layer

with the web browser that delivers the HTML at the top of this list and the actual DBMS at the bottom (say SQL Server, by best practice including stored procedures etc. which contribute towards the BLL).

The architects of the commerce starter kit have chosen to combine BLL and DAL to 'reduce the complexity of the application'. Thus the commerce starter kits implements the following layers with the following technologies:

USL: web forms and user controls
BLL/ DAL: 7 components closely mapping to the physical database design (e.g. orders and shopping cart)*

* note that there is no necessity that the mapping should be so simple; in fact the BLL would normally abstract away from the underlying database design but in this case the application is relatively simple and the BLL and DLL have also been combined making the close mapping more sensible.

We'll explore the system architecture as we discuss the system functionality rather than detailing at this point. The reader may prefer to review the documentation available with the starter kit so as to have a more detailed appreciation of the architecture and implementation at this stage.

Let's take a very quick look at the implementation of the shopping cart functionality as an example of the standard approach within the CSK (Commerce Starter Kit). We’ll return to a fuller consideration of the shopping cart in the next article in this series.

The CSK accepts a productID in the querystring and instantiates a shoppingCart object from the BSL. Using the context of the current web site user – note that the CSK relies on cookies to do so – the user is either allocated or associated with an existing cart and the productID passed into the BSL for addition to this cart. The code is as follows:

If Not Request.Params("ProductID") Is Nothing Then
  Dim cart As ASPNET.StarterKit.Commerce.ShoppingCartDB = New ASPNET.StarterKit.Commerce.ShoppingCartDB

  ' Obtain current user's shopping cart ID
  Dim cartId As String = cart.GetShoppingCartId()

  ' Add Product Item to Cart
  cart.AddItem(cartId, (Request.Params("ProductID")), 1)
End If

This demonstrates the standard approach from the USL: instantiate the pertinent BSL object and call methods of this object handling the passing of input data and the subsequent use and or display of output data accordingly.

Summary and what's next

In this first article in the series we've introduced the problem domain and the overall solution architecture we'll be using. In the next article we’ll focus on one area of functionality – the shopping cart – and how we alter the base implementation to support the more complex data requirements of the Lockers project.

References

Commerce Whitepaper
www.asp.net

Beginning ASP.NET E-Commerce
Darie and Watson
Wrox