Welcome Guest, Not a member yet? Register   Sign In
Undefined Index in Extended Cart Library
#1

[eluser]tkaw220[/eluser]
Hi,

I extended my Cart library (MY_Cart) and is receiving below errors when updating the cart:

Undefined index: price
Undefined index: ini_price
Undefined index: books
Undefined index: toys

Below is my code (line that caused this issue made bold):

function update($items = array())
{
// Was any cart data passed?
if ( ! is_array($items) OR count($items) == 0)
{
return FALSE;
}

// You can either update a single product using a one-dimensional array,
// or multiple products using a multi-dimensional one. The way we
// determine the array type is by looking for a required array key named "id".
// If it's not found we assume it's a multi-dimensional array
$save_cart = FALSE;
if (isset($items['rowid']) AND isset($items['qty']) OR isset($items['books']) OR isset($items['toys']))
{
if ($this->_update($items) == TRUE)
{
$save_cart = TRUE;
}
}
else
{
foreach ($items as $val)
{
if (is_array($val) AND isset($val['rowid']) AND isset($val['qty']))
{
if ($this->_update($val) == TRUE)
{
$save_cart = TRUE;
}
}
}
}

// Save the cart data if the insert was successful
if ($save_cart == TRUE)
{
$this->_save_cart();
return TRUE;
}

return FALSE;
}

// --------------------------------------------------------------------

/**
* Update the cart
*
* This function permits the quantity of a given item to be changed.
* Typically it is called from the "view cart" page if a user makes
* changes to the quantity before checkout. That array must contain the
* product ID and quantity for each item.
*
* @access private
* @param array
* @return bool
*/
function _update($items = array())
{
// Without these array indexes there is nothing we can do
if ( ! isset($items['qty']) OR ! isset($items['rowid']) OR ! isset($this->_cart_contents[$items['rowid']]))
{
return FALSE;
}

// Prep the quantity
$items['qty'] = preg_replace('/([^0-9])/i', '', $items['qty']);
$items['price'] = preg_replace('/([^0-9\.])/i', '', $items['price']);
$items['ini_price'] = preg_replace('/([^0-9\.])/i', '', $items['ini_price']);
$items['books'] = preg_replace('/([^0-9\.])/i', '', $items['books']);
$items['toys'] = preg_replace('/([^0-9\.])/i', '', $items['toys']);


// Is the quantity a number?
if ( ! is_numeric($items['qty']))
{
return FALSE;
}

// Is the new quantity different than what is already saved in the cart?
// If it's the same there's nothing to do
if ($this->_cart_contents[$items['rowid']]['qty'] == $items['qty'] AND $this->_cart_contents[$items['rowid']]['price'] == $items['price'] AND $this->_cart_contents[$items['rowid']]['books'] == $items['books'] AND $this->_cart_contents[$items['rowid']]['toys'] == $items['toys'])
{
return FALSE;
}

// Is the quantity zero? If so we will remove the item from the cart.
// If the quantity is greater than zero we are updating
if ($items['qty'] == 0)
{
unset($this->_cart_contents[$items['rowid']]);
}
elseif ($items['qty'] != 0 AND $items['price'] != 0)
{
$this->_cart_contents[$items['rowid']]['qty'] = $items['qty'];
$this->_cart_contents[$items['rowid']]['price'] = $items['price'];
$this->_cart_contents[$items['rowid']]['ini_price'] = $items['ini_price'];
$this->_cart_contents[$items['rowid']]['books'] = $items['books'];
$this->_cart_contents[$items['rowid']]['toys'] = $items['toys'];
}
else
{
$this->_cart_contents[$items['rowid']]['qty'] = $items['qty'];
}

return TRUE;
}

How can I fix it?

Many thanks.




Theme © iAndrew 2016 - Forum software by © MyBB