A worked shopping cart example
A shopping cart is a useful teaching example because it touches almost every idea in this track at once, without being large.
The pieces
- A product list. Reads the catalogue from a database and shows it.
- An add button. Adds one product to the visitor's cart.
- The cart itself. Held in session while the visitor browses.
- A checkout page. Writes the order to the database and clears the cart.
Why the cart lives in session
A cart belongs to one visitor and lasts for one visit, which is exactly what session state offers. When the visitor checks out, the order moves into the database where it can last forever.
Where to see a working version
The Beginner Web Site Kit includes a complete shopping cart sample with source code and a database you can restore. Read this lesson first, then open the code and follow one page at a time.
To store and read the catalogue data yourself, continue to talking to a database with ADO.NET.