Welcome Guest, Not a member yet? Register   Sign In
Delete specific row in the Cart
#1

[eluser]Unknown[/eluser]
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
Code:
$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
Code:
$this->cart->insert()
instead of
Code:
$this->cart->update()
and set the quantity to 0;

Example:

Code:
$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:

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


And instead of these line:

Code:
// 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 :

Code:
// 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;







Theme © iAndrew 2016 - Forum software by © MyBB