How to remove the single cart item using codeignit

2020-07-20 06:52发布

I am using codeigniter cart class for my shopping cart project. I have number of items on the cart. Now I do have cart row id. Now what exactly i need to do is, need to remove the particular item from the cart not all the contents(Destroying cart).

$cartcontents = $this->cart->product_options($rowid); 

and unseting all contents. but doesn't works out. Please do help you anybody have an idea. Thank You.

4条回答
欢心
2楼-- · 2020-07-20 07:13

Create a remove button at view page and add row id with link. After that create a function and pass row id and put quantity 0 and pass that array in update function.

public function remove_cart_product($data) {
  $row_id=$data;
  $qty=0;
  $array=array('rowid' =>$row_id ,'qty'=>$qty );
  $this->cart->update($array);
  print_r($this->cart->contents());exit();
}
查看更多
在下西门庆
3楼-- · 2020-07-20 07:22
$data = array(
'rowid'   => '30ef30b64204a3088a26bc2e6ecf7602',
'qty'     => 0
);

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

use this

查看更多
爷的心禁止访问
4楼-- · 2020-07-20 07:24

If the quantity is set to zero, the item will be removed from the cart.

$data = array(
           'rowid' => 'b99ccdf16028f015540f341130b6d8ec',
           'qty'   => 0
        );

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

Here, set QTY = 0 then it will be removed.

查看更多
Animai°情兽
5楼-- · 2020-07-20 07:30

Use "removeCartItem" function in your controller to do this...

function removeCartItem($rowid) {   
        $data = array(
            'rowid'   => $rowid,
            'qty'     => 0
        );

        $this->cart->update($data);
}
查看更多
登录 后发表回答