So, I have a shopping cart that allows you to select a JAR file and then select the contents of the JAR file (i.e. options).
When the product is "added to the cart" the following script is ran:
$productID = $_POST['id'];
$action = $_POST['action'];
if(!$_POST['id'] | !$_POST['action'])
{
$productID = $_GET['id'];
$action = $_GET['action'];
}
// Creates the array of the options chosen for the item.
$optionsSelected = array();
if (!empty($_POST['productOption']))
{
foreach ($_POST['productOption'] as $options)
$optionsSelected[] = $options;
switch($action) {
case "add":
$_SESSION['cart'][$productID]++;
$_SESSION['options'.$productID]= $optionsSelected;
header('location: /shop/cart');
break;
case "remove":
$_SESSION['cart'][$productID]--;
unset($_SESSION['options'.$productID]);
if($_SESSION['cart'][$productID] == 0)
{
unset($_SESSION['cart'][$productID]);
unset($_SESSION['options'.$productID]);
}
header('location: /shop/cart');
break;
}
And then it is displayed out like so in the shopping cart:
<?php if (count($_SESSION['options'.$id]) > 0): ?>
<?php foreach($_SESSION['options'.$id] as $key => $options): ?>
<p><?php echo $options; ?></p>
<?php endforeach; ?>
<?php endif; ?>
(This is only the portion for the options. To see the full shopping cart page code click here (recommended))
Right now, the session for the options get overwritten if you go and add another product with the same ID to the cart with different options. And that first set of options is gone!
I want to make the shopping cart realize that there is already a session of options set for the ID and that it needs to make something different to display an entirely new line in the shopping cart to display it and preserve both option sets for the product id. To see the website, visit candykingdom.org/shop/products.php.
I have no idea where to go from here. I have been searching and staring at my screen for days, but I haven't gotten anywhere. How can I accomplish this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…