[eluser]Unknown[/eluser]
Hello,
I`m using the Cart class to build a shooping card and I want to check before Inserting to the
cart if the item exists and if so I want to increment its quantity by one , I`m using the following code , But it does not work with me , any help will be appreciated
Code:
function add() {
$this->load->model('Cart_Model');
$Product = array_shift($this->Cart_Model->get_by_id($this->input->post('PID')));
$data = array(
'id' => $Product->id,
'name' => $Product->product_name,
'price' => $Product->price,
'qty' => 1
);
$cartCont = $this->cart->contents();
if (!empty($cartCont) AND isset ($cartCont[md5($Product->id)])) {
$cartCont[md5($Product->id)]['qty']++;
}
if ($this->cart->insert($data)) {
redirect('products');
}
}