I have struggled to find a solution to a simple shopping cart with $_SESSION
.
I kept it very simple and this is my code right now
if ( Input::isPos
Try using the size as a key to an extra dimension in your multidimensional array. Your current code only allows you to have one size per item.
You would end up with something like:
if ( Input::isPost('add') ) {
$id = Input::get('id');
$qta = Input::post('qta');
$size = Input::post('size');
if ( !isset($_SESSION['cart']) ) {
$_SESSION['cart'] = array();
}
if ( array_key_exists($_SESSION['cart'][$id][$size]) ) {
$_SESSION['cart'][$id][$size] += $qta;
} else {
$_SESSION['cart'][$id][$size] = $qta;
}
}