Chapter 11. The Winestore 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. 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 chapter is the second of four that outline the complete winestore application. As discussed in Chapter 10, the descriptions of the scripts aren’t comprehensive, and we assume you’ve read Chapter 2 to Chapter 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 chapter.

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 chapter perform the following functions:

Present the home page

Display the Hot New Wines panel based on the examples developed in Chapter 4 and Chapter 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 ...

Get Web Database Applications with PHP, and MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.