I'm using sessions for adding products to a shopping cart. When a customer hits the "Order this Item" from a particular product page, they are directed to orderitem.php?prodID=blah
This page has a long form which is filled out by the customer. At the end of the form is the typical "Add to Cart" button.
So now i need to determine what to do when this button is clicked. It seems like most shopping carts then take you to the actual cart and show you the contents. This is what I'd like to do. However, I cannot figure out in my tiny head how to make it happen, and I'll explain why.
What I can figure out is the following. When a customer hits "Add to Cart", I can send them to a "Added to Cart" page, showing the specifics of the item added. On this page, I can then pull whatever necessary values from $POST and save them to my session.
$prodID = $_POST['prodID'];
$productDetails = array("qty"=>$_POST['qty'],
"pColor"=>$_POST['pColor'],
"iColor"=>$_POST['iColor'],
"IHdate"=>$_POST['IHdate']);
$_SESSION['cart'][$prodID] = $productDetails;
if (isset($_SESSION['numitems'])) {
$_SESSION['numitems']+=1;
}
else {
$_SESSION['numitems'] = 1;
}
Then on this page, I can give the customer a link to view the contents of their cart. The mycart.php page will basically have a loop that runs through the SESSION and prints all the cart contents. This all makes sense to me.
But how can I combine this into one step? How do I add an item to the cart on the cart page itself.
Would I do this by testing the $POST function for any of the possible values that would be there if indeed the link came from an "Order this Item" page? Could I do a the following:
if (isset($_POST['qty']) {
// this signals that we came to mycart.php from an ordering page, or
// more specifically, from an order that was posted.
// So FIRST, add the current posted order to the session array
}
THEN follow the normal mycart.php implementation.
Would that be how it works?
Thanks.