8.1. Designing the Shopping Cart

In its most basic form, a shopping cart is nothing more than code that maintains a list of selected items a shopper selects until he or she is ready for purchase. Remember that HTTP is a stateless protocol. Each page request takes place without knowledge of previous requests or expectations for future requests, so the list of items is generally saved using some session or cookie-based mechanism. This cart will use PHP's built-in session handling functionality.

A shopping cart class will keep track of the selected items and offer methods to add and remove items. A pair of front-end scripts will act as a virtual storefront and integrate the class to allow users to:

  • View various product categories, a list of products within each category and details of each product

  • Add and remove items in a virtual shopping cart

  • Change an item's quantity in the cart

An administrative interface will also be built to allow you to easily manage the available categories and products. The interface will offer the following functionality:

  • Add, delete, and modify categories

  • Add, delete, and modify products within the categories

You've seen in previous projects how the Ajax paradigm allows for a more intuitive interaction between users and forms and so the administration interface will make use of JavaScript in this manner.

Get PHP and MySQL®: Create-Modify-Reuse 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.