Shopping Cart

In this tutorial, we introduce the shopping cart developed for the online winestore. The shopping cart is typical of those used in online stores: the user can add items to the cart and manage the quantities of the different items. The solution we outline is scalable and practical.

The cart data is stored in the winestore database tables, and only one session variable per user is required to track the cart's identity.

This tutorial is the second of four that outline the complete winestore application. As discussed in tutorial 10, the descriptions of the scripts aren't comprehensive, and we assume you've read tutorial 2 to tutorial 9 as background. Also, we encourage you to install a local copy of the application and to view, edit, and use the scripts while reading this tutorial.

We present here the four scripts that manage the shopping cart, a fifth script that produces the home page that includes the Hot New Wines panel, and a sixth script that manages redirection to other pages when the user clicks on buttons.

The scripts in this tutorial perform the following functions:

Present the home page
Display the Hot New Wines panel based on the examples developed in tutorial 4 and tutorial 5
View the shopping cart
Query the database and display the contents of the user's shopping cart
Add items to the cart
Add a quantity of a specific wine to the user's shopping cart
Empty the cart
Delete all the items in the cart and remove the cart
Update quantities
Manage changes to the number of bottles of wines in the cart, including deletion of one or more wines
Process button clicks and redirect the browser
Manage the redirections required when the user presses the different buttons on each of the winestore pages

As with the other modules in the winestore, the shopping cart isn't a production system. The scripts presented here illustrate the practice of developing a web database application. Techniques shown include database interactivity, concurrency management, using sessions, and one- and two-component querying.