CodeIgniter Forums
Need Help With The Cart Class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Need Help With The Cart Class (/showthread.php?tid=44972)



Need Help With The Cart Class - El Forum - 09-02-2011

[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 Smile

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');
        }
    
    }