EllisLab text mark
Advanced Search
     
Delete specific row in the Cart
Posted: 30 November 2011 04:04 AM   [ Ignore ]
Joined: 2011-11-30
2 posts

I try to delete a specific row in the cart using the cart library.
which I noticed that it has no delete function. Some forums suggest that
you can use update function

$this->cart->update() 

and set the quantity or
price perhaps to 0. But!, still for me it doesn’t work.

I explored the library and made few changes.
I used

$this->cart->insert() 
instead of
$this->cart->update() 

and set the quantity to 0;

Example:

$data = array(
   
'id'   => $id,
   
'qty'     => '0',
   
'price'   => '0',  
   
'name'    => 'DELETED'
   
);
   
$this->cart->insert($data); 

these are the lines that need to be change in the library.

Remove or comment the line:

$items['qty'trim(preg_replace('/(^[0]+)/i'''$items['qty'])); 
$items['price'trim(preg_replace('/(^[0]+)/i'''$items['price'])); 


And instead of these line:

// let's unset this first, just to make sure our index contains only the   data from this submission
unset($this->_cart_contents[$rowid]);  
  
// Create a new index with our new row ID
$this->_cart_contents[$rowid]['rowid'$rowid;
 
// And add the new items to the cart array   
foreach ($items as $key => $val)
{
     $this
->_cart_contents[$rowid][$key] $val;
}
// Woot!
return TRUE

Change it to this :

// let's unset this first, just to make sure our index contains only the data from this submission
  
unset($this->_cart_contents[$rowid]);  
  
  
// Create a new index with our new row ID

  
if($items['qty'== 0
  
{
   
unset($this->_cart_contents[$rowid]['rowid']);
  
}
  
else
  
{
   
// And add the new items to the cart array 
   
$this->_cart_contents[$rowid]['rowid'$rowid;
   foreach (
$items as $key => $val)
   
{
    $this
->_cart_contents[$rowid][$key] $val;
   
}
  }
  
return TRUE