O'Reilly logo

PHP Advanced for the World Wide Web: Visual QuickPro Guide by Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing a Shopping Cart

The most important aspect of the e-commerce site is the shopping cart itself. There are many types of carts out there, from a programming perspective, for many different purposes. What I'm going to write here is a generic cart class that can be adapted towards other e-commerce uses. But first, let's think about what a shopping cart should do:

  • Allow the customer to add items to the cart

  • Allow for different quantities of each item

  • Allow the customer to alter the quantities of an item

  • Allow the customer to remove an item

I'm going to write a shopping cart class that does all of this as well as displays the cart's contents. This last feature might also be placed in an extended class, as its particulars may change from application ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required