我必须实现优惠券,并且需要显示折扣价格。我想更新$this->cart->total()
的值,而不是更新产品。
我知道$this->cart->total()
会返回总金额,但如何更新此金额?
我确信您可以在会话中更新它。
$_SESSION['cart_contents']['cart_total'] = INSERT CORRECT TOTAL HERE;
或者,您可以在会话中创建一个名为coupon_discount的新购物车项目,并在其中添加该值。
然后,当你在视图中显示这个值时,你可以只显示一个减去另一个。
您在购物车中添加其他字段,如下所示:
$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.