Perhaps this is desired (?) - but when a product has attributes (ie, size), when a user adds to the cart - if the go back to the product page, it doesn't show how many are in the cart (because the product_id ends up as a hash) - code fix (see **MC) - obviously there's a performance hit of iterating through the product list and strcmp, but assuming carts don't get too big - i'm guessing it's not an issue:
/**
* Method to get the quantity of an item in the cart
*
* @param mixed product ID of item to check
* @return decimal the quantity of the item
*/
function get_quantity($products_id) {
$this->notify('NOTIFIER_CART_GET_QUANTITY_START');
if (isset($this->contents[$products_id]))
{
$this->notify('NOTIFIER_CART_GET_QUANTITY_END_QTY');
return $this->contents[$products_id]['qty'];
}
else
{
// **mc check for attributes
if (is_array($this->contents))
{
reset($this->contents);
$total_items = 0;
while (list($listproducts_id, ) = each($this->contents))
{
if(substr_compare($listproducts_id, $products_id.":", 0, strlen($products_id))==0)
{
$total_items += $this->get_quantity($listproducts_id);
}
}
if ($total_items > 0)
{
$this->notify('NOTIFIER_CART_GET_QUANTITY_END_QTY');
return $total_items;
}
}
// ** endmccheck
}
$this->notify('NOTIFIER_CART_GET_QUANTITY_END_FALSE');
return 0;
}
/**
* Method to check whether a product exists in the cart
*
* @param mixed product ID of item to check
* @return boolean
*/
function in_cart($products_id) {
// die($products_id);
$this->notify('NOTIFIER_CART_IN_CART_START');
if (isset($this->contents[$products_id]) )
{
$this->notify('NOTIFIER_CART_IN_CART_END_TRUE');
return true;
}
else
{
// **mc check for attributes
if (is_array($this->contents))
{
reset($this->contents);
while (list($listproducts_id, ) = each($this->contents))
{
if(substr_compare($listproducts_id, $products_id.":", 0, strlen($products_id))==0)
{
$this->notify('NOTIFIER_CART_IN_CART_END_FALSE');
return true;
}
}
}
// ** endmccheck
}// end else
$this->notify('NOTIFIER_CART_IN_CART_END_FALSE');
return false;
}
Bookmarks