Welcome Guest, Not a member yet? Register   Sign In
Problems with the cart class
#6

[eluser]nelson.wells[/eluser]
After looking at the cart->update function, it will only update the quantity. Does anyone know if they plan on making that function more flexible in CI 2? I don't like that the update function is only useful for updating the price. If they don't plan on making it more flexible, maybe I will lend my hand at it...

Here is a quick and dirty solution. You should take more validation and error checking steps, but this will get the job done in a hurry.

Code:
class MY_Cart extends CI_Cart
    {
        function update_price($items = array())
        {
            //only update the cart if the rowid and price keys were passed
            if( isset($items['rowid']) && isset($items['price']) )
            {
                $this->_cart_contents[$items['rowid']]['price'] = $items['price'];
                
                $this->_save_cart();
                
                return true;
            }
            else
            {
                 return false;
            }
        }
    }

Put that in the file MY_Cart.php in the libraries folder. You call it like this

Code:
$data = array(
        'rowid' => $rowid,
        'price' => $new_price
);

$this->cart->update_price($data);

Please note that the function does not accept an array of items. You'll have to do some additional programming to do that Smile


Messages In This Thread
Problems with the cart class - by El Forum - 03-18-2010, 09:59 AM
Problems with the cart class - by El Forum - 03-25-2010, 05:58 AM
Problems with the cart class - by El Forum - 03-25-2010, 08:29 AM
Problems with the cart class - by El Forum - 03-25-2010, 08:35 AM
Problems with the cart class - by El Forum - 03-25-2010, 09:03 AM
Problems with the cart class - by El Forum - 04-02-2010, 04:35 PM
Problems with the cart class - by El Forum - 04-02-2010, 08:19 PM
Problems with the cart class - by El Forum - 04-13-2010, 10:57 PM
Problems with the cart class - by El Forum - 11-01-2010, 04:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB