Chapter 18. The Shopping Cart
In this chapter, 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. However, it’s also a little different: unlike many other implementations, the cart data is stored in database tables, and one session variable per user tracks the cart’s identity.
This chapter is the third of five that outline the complete winestore application. We present here the four scripts that manage the shopping cart and a fifth script that produces the home page of the winestore. The scripts in this chapter perform the following functions:
- Display the home page
Shows new wines that have recently been reviewed. The script also includes embedded links that allow the user to add items to their cart; this is one part of the one-component querying strategy discussed in Chapter 6, and the other part is a feature of the script that adds items to the cart, discussed next.
- Add items to the cart
- View the shopping cart
Queries the database and displays the contents of the user’s shopping cart. This demonstrates basic querying techniques from Chapter 6, combined with the
winestoreFormTemplateclass discussed in Chapter 16.
- Empty the cart