5.4. Building the Shopping Cart Scripts

The shopping cart provides functionality for the following three areas of responsibility:

  • The product information: The shopping cart displays the product information that's in the online catalog. It displays two types of Web pages — a page that displays the categories of products and a page that displays the product information for a selected product. The script adds items from the product information Web page to the shopping cart.

  • The shopping cart: The shopping cart stores information about items that the customer selects. The information for items that the customer puts in the shopping cart is stored in the database, and an order number is assigned to the order and saved in a session variable so that the order information can be retrieved from the database. The customer can see the currrent items in her shopping cart at any time. The customer can add and remove items or change the quantity of items at any time until she submits the order.

  • The order: The shopping cart gathers information about the order. It collects the information necessary to complete the customer's purchase. The price of the all the ordered items is summed. A form is provided to collect and validate shipping information. All costs and charges, including shipping costs and sales tax, are computed and applied to the order total. The credit card information is collected and processed.

The functionality of the shopping cart is provided by three PHP scripts, one for each area ...

Get PHP & MySQL® Web Development All-in-One Desk Reference for Dummies® now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.