If someone wants to use the shopping cart script above, just make sure that, if your products have different sizes, colors, styles, etc, make sure you change
if (isset($_POST['submit']) && $_POST['submit'] == 'Add Items')
{
extract($_POST);
if (isset($_SESSION['cart'][$product_id])) // if the item already exists, add to the quantity
{
$_SESSION['cart'][$product_id]['quantity'] += $quantity;
}
else
{
$_SESSION['cart'][$product_id] = array(
'quantity' => $quantity,
'size' => $size,
'color' => $color,
'style' => $style,
'price' => $price,
'name' => $name
);
}
}
to
if (isset($_POST['submit']) && $_POST['submit'] == 'Add Items')
{
extract($_POST);
$PROD = "$product_id$size$color$style";
if (isset($_SESSION['cart'][$PROD])) // if the item already exists, add to the quantity
{
$_SESSION['cart'][$PROD]['quantity'] += $quantity;
}
else
{
$_SESSION['cart'][$PROD] = array(
'quantity' => $quantity,
'size' => $size,
'color' => $color,
'style' => $style,
'price' => $price,
'name' => $name
);
}
}
Otherwise it would be just adding the quantity to the item you choose, ignoring the size, color, style, etc...