Search code examples
codeignitercodeigniter-2cart

Unable to add same product more than once in CodeIgniter cart


I am developing a shopping cart using codigniter 2.1.4. My issue is that I am unable to add same product more than one time in cart. But I can update the quantity in cart. So my requirement is that when cart the item for second time quantity should be increment to 2.


Solution

  • In your Cart.php replace the following code

    unset($this->_cart_contents[$rowid]);
    

    with this

    if(isset($this->_cart_contents[$rowid]))
    {
    $this->_cart_contents[$rowid]['qty']++;
    return $rowid;
     }
    
    unset($this->_cart_contents[$rowid]);