|
Managing Web Operations
LAB: Using Cookies and Sessions to Implement a Shopping Cart -- Part 2
Add the purchase to the cart ...
- In your editor open sweetscomplete/purchase.php
- At the top of the file include and assign a variable to Products.php
- Filter and validate from $_GET productID, qty and price
- If validation fails, set a failure code in a cookie "status"
- If validation succeeds:
- Make a call to $products->addProductToCart($productID, $qty, $price)
- Set a success code in a cookie "status"
- Redirect back to "products.php"
Modify products.php ...
- In your editor open sweetscomplete/products.php
- Check for the cookie "status"
- If success, display a message "Added to your cart, thanks!"
- If failure, display a message "Sorry: problem adding this item to your cart!"
- Make sure products.php links to "cart.php"
Test by settings params in URL ...
- From your brower enter: http://localhost/sweetscomplete/purchase.php?productID=1&qty=1&price=1.11
- At the top of the page click "Shopping Cart"
- Verify that the product appears in the cart
|
|