更新codeigniter中的购物车总数

时间:2018-12-13 12:34:17

标签: php codeigniter

我必须实施优惠券,并且需要显示折扣价。 我想更新$this->cart->total()的值,而不是更新产品。

我知道$this->cart->total()将返回总金额,但是如何更新此金额?

2 个答案:

答案 0 :(得分:0)

我很确定您可以在会话中进行更新。

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

或者您可以在会话中创建一个名为coupon_discount的新购物车商品,并在其中添加该值。

然后,当您在视图中显示该值时,您可以只显示一个值减去另一个值。

答案 1 :(得分:0)

您可以在购物车中添加其他字段,如下所示:

            $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.