Hey.
So i was working on a shopping cart that didn't focus much on having a database to support the information.
I have a snippet of code that checks to make sure there is no dublicates. if there is it just changes the quantity to the right one.
but if a user inputs a quantity in the quantity box on the other page where the add to cart button is it. adds duplicates and my code doesn't seem to catch it.
Below is the code in question.
// Break Current Session
$current_cart = explode("|",$_SESSION['cart']);
$length = count($current_cart);
echo $length;
foreach($current_cart as $x => $v)
{
$temp = explode(",",$current_cart[$x]);
if($temp[0] == $type && $temp[1] == $size)
{
$temp[0] = $type;
$temp[1] = $size;
$temp[2] = (int)$quantity + (int)$temp[2];
$temp[3] = number_format($price, 2, '.', ' ');
$current_cart[$x] = implode(',',$temp);
}
else
{
$current_cart[$x+1] .= implode(",",$item);
}
}
$new_cart = implode("|",$current_cart);
$_SESSION['cart'] = $new_cart;
}
else
{
$_SESSION['cart'] = implode(",",$item);;
}
Mostly works with SESSIONS and stuff
Having Help ASAP would be nice as this is important project to my client.