I have not started with OO and do not know if that is the reason it does not work for you.
The check in part is simply this:
if(array_key_exists($prdct_id, $this->cartArray))
{
// This product item already exist, update cart
$this->cartArray[$prdct_id] += $qty;
}
else
{
// just add this new item to cart
$this->cartArray[$prdct_id] = $qty;
}
My simple test code (without using session data as global container or POST data) works with the above construction.
function checkInItem(&$cart, $id, $qty)
{
if(array_key_exists($id, $cart))
{
// This product item already exist, update cart
$cart[$id] += $qty;
}
else
{
// just add this new item to cart
$cart[$id] = $qty;
}
}
// current cart items
$cartItems = array('prodId_1' => 2, 'prodId_5' => 1, 'prodID_17' => 12);
// check in data for item 1
$item1_id = 'prodId_7';
$item1_qty = 1;
// check in data from item 2
$item2_id = 'prodId_5';
$item2_qty = 3;
// Look at the cart before
echo "Cart contains initially: <br>";
print_r($cartItems);
echo "<br>";
echo "<br>Adding item1 with product ID = $item1_id and qty = $item1_qty<br>";
// check in item1 into cart
checkInItem($cartItems, $item1_id, $item1_qty);
echo "Adding item2 with product ID = $item2_id and qty = $item2_qty<br>";
// check in item2 into cart
checkInItem($cartItems, $item2_id, $item2_qty);
// Look at the cart after items added
echo "<br>Cart contains after the items were added: <br>";
print_r($cartItems);
echo "<br><br>";
Output is
Cart contains initially:
Array ( [prodId_1] => 2 [prodId_5] => 1 [prodID_17] => 12 )
Adding item1 with product ID = prodId_7 and qty = 1
Adding item2 with product ID = prodId_5 and qty = 3
Cart contains after the items were added:
Array ( [prodId_1] => 2 [prodId_5] => 4 [prodID_17] => 12 [prodId_7] => 1 )