更新codeigniter中的购物车总金额

I have to implement coupon and needs to show discounted price. I want to update the value of $this->cart->total() instead of updating products.

I know that $this->cart->total() will return total amount, but how to update this amount?

I'm pretty sure you can just update it in the session.

$_SESSION['cart_contents']['cart_total'] = INSERT CORRECT TOTAL HERE;

Or you can create a new cart item in your session called coupon_discount and add that value there.

Then when you show that value in your view you can just show one minus the other.

You add additional fields in your cart like this:

            $discount = 50.00; //depends on your logic

            $data = array(
                    'id'=> random_string('alnum', 16).time(),
                    'product_code' => $product_id_,
                    'qty'     => $qty,
                    'price'   => $price-$discount, //your cart total() is net of discount already
                    'orig_price'=>$orig_price,
                    'name'    => $product_name,
                    'photo' => $photo,
                    'category' => $category,
                    'uom'=>$uom,
            );

            $this->cart->product_name_safe = FALSE; //this is okay because i got the name from our database not from user input.
            $this->cart->product_id_rules = '[:print:]'; //this will allow special chars in product code 
            $this->cart->product_name_rules = '[:print:]'; //this will allow special chars in product name 
            $this->cart->insert($data); //add item in your cart.