Web shopping carts are common tools these days. With a shopping cart, you browse an online catalog, adding items to your cart as you shop. This is similar to grocery shopping.
The whole shopping cart idea does not have to be used only for e-commerce sites. A shopping cart program can be used to hold user preferences, vote tallies, scores, and just about anything else you can think of.
The shopping cart system we put together in this chapter is not a complete, ready-to-use e-commerce application. Instead, we use some of the tools we have already built and create a framework we can build upon. We can build this into an e-commerce application or use it simply to keep inventory of some items.
If you remember back in Chapter 12, we create a SOAP-based catalog. We use that catalog as our “product catalog” in this example. Also, if you can dig up the code from the tied-hash chapter, we use much of that as well. To implement a shopping cart, we need to support the concept of sessions. But HTTP has no support for sessions—servers know only about individual unrelated requests for URLs. But by using cookies, we can implement sessions. What’s new in this chapter is that we store the contents of the shopping cart as part of the per-session data. The tied-hash method we’ve worked on is perfect for this.
The features our shopping cart application will have are:
View catalog listing
Add items to cart
Remove items from cart
Display specific items
Show cart with totals
Show invoice with totals
These features should be a great start to any sort of Web application needing a shopping cart.
We use templates again for our HTML output. Using templates really can make things easier by separating the Perl code from the HTML. You can find the code for these templates at the end of this chapter and on this book’s companion Web site.