[英]Update total amount of cart in codeigniter
我必須實施優惠券,並且需要顯示折扣價。 我想更新$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.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.