MIS 324 - Intermedidate Web Development Management Fall 2009

Last updated: 11/7/2008 10:42:10 AM

Assignment 7 - Shopping Cart

A web-based shopping cart can use cookies, a database, or a session object for storing the items in the cart. The database approach is used by Amazon and other most high-quality commercial sites becuase it can persist indefinitely and can be retrieved from multiple locations. Storing shopping cart data in a database also allows user behavior to be analyzed (data mining) for insights on how to improve the site and its featrues.  

Shopping carts usually do not require users to sign-in since this may deter people from putting items in their cart. Since we do not necessarily know the customer's identiry we use their ASP.NET SessionID to associate each user with their shopping cart. SessionIDs are generated automatically by ASP.NET (and most server-side technologies) and are stored in a cookie on the user's computer. It is a string of 24 random characters and numbers that uniquely identifies each ASP.NET session. The session ID may be retrieved with the syntax "Session.SessionID". ASP.NET will generate a new session ID each time the page loads unless some data is stored in the session. To force it to retain the same session ID include in the page_load subroutine something like:

Session["PutSomethingInSession"] = "Go Vikings"

We hope that each user will log in during their session so that we can associate the items in the cart their CustomerID. 

Database: Retrieving product information from Amazon web services is slow we will store the essential product attributes in the shopping cart. Your database needs a table named tblCart to store the cart items. Create a new table in your database named tblCart with the following fields:

ShoppingCart Class: The shopping cart class contains the underlying functionality of a shopping cart: adding items, updating quantities, removing items, listing items, etc. The shopping cart's functionality is a good candidate for a class because:

  1. its features are needed in several .aspx pages (productPage, SearchBrowse, ShoppingCart and Checkout.)
  2. it represents a real-world object with properties and methods.
  3. it consist of a lots of code that is easily hidden behind a small class interface.

Add the shopping cart class to your application by pasting the source code for the shopping cart class into a new file in your App_Code folder. This will add shopping cart functionality to your application as shown here:

Shopping cart properties and methods:

 
AddToCart method:


ListItemsInCart method:

 

Change the name of the database in the ShoppingCart class from "SandvigMusicStore" to name of your music store database (name in web.config file).

1. SearchBrowse.aspx - Items are added to the shopping cart from the ProductPage and optionally the SearchBrowse page. The sample SearchBrowse.aspx (source) page shows how to handle "Add to cart" click events and retrieve data from dataList control.

When a use clicks on the "add to cart" button the click event is captured by the button's parent control, the datalist. The datalist calls a handler for the event that adds the information to tblCart using the ShoppingCart class.

Note: Amazon web services should not retrieve product information when the user clicks the "add to cart" button and causes a page postback. Make sure that Amazon web services is called only the first time the page loads by calling it from inside "if (!Page.IsPostBack) ..." within the Page_Load subroutine.

2. ShoppingCart.aspx - The overall logic of the database cart is shown in this basic database shopping cart ( source code). Modify this sample to display product images, item price information, shipping and total cost..


To submit your assignment for grading send an email with the URLs for your assignment to:

  1. Professor Sandvig at (note: this address is for homework assignments only. Please send correspondence to )
  2. cc. Kraig Pencil ( )
  3. cc. a copy to yourself

The subject line of your email should read "MIS324 AXX YourName" where XX is the assignment number. Please check that your URLs are correct before submitting them for grading. Files with incorrect URLs will not be graded.