I use the following code in my controller for adding product items to the session:
$app = JFactory::getApplication();
$input = $app->input;
$itemid = $input->get('itemid');
$quan = $input->get('quan');
$session = JFactory::getSession();
$cart = $session->get('cart', array());
$cart['items'][] = array('itemid' => $itemid, 'quan' => $quan);
$session->set('cart', $cart);
It works, but if I add the same product with the same ID to the session once more it doesn't update the quantity of such product but adds the same product as new item. So I need something like:
if($itemid == 'itemid') {
$cart['items'][] = array('quan' => 'quan'+$quan); // i.e. current quan + new quan
} else {
$cart['items'][] = array('itemid' => $itemid, 'quan' => $quan);
}
It doesn't work of course