[Phplib-trackers] [ phplib-Bugs-496254 ] cart.inc add_item malfunction
Brought to you by:
nhruby,
richardarcher
|
From: <no...@so...> - 2001-12-23 10:22:41
|
Bugs item #496254, was opened at 2001-12-23 02:22 You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=403611&aid=496254&group_id=31885 Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: cart.inc add_item malfunction Initial Comment: In module cart.inc, there is a function add_item(). If an item exists in the cart then it should add pieces. Problem: If an item exists in the cart and it's the first in cart (ARRAY-INDEX = 0), then no pieces are added. Instead a new = dupe entry is created. Here is the code from cart.inc: function check($art) { if (!is_array($this->item)) return array(false, 0); reset($this->item); while(list($item, $attr) = each($this->item)) { if (isset($attr["art"]) && ($attr["art"] == $art)) { return array($item, $attr["num"]); } } return array(false, 0); } If item in cart, check() returns an array of ARRAY-INDEX (number) and NUMBER (number) of the item. If not in cart, check() returns FALSE (boolean) and 0 (number). function add_item($art, $num) { ## Check to see if we already have some of these list($item, $have) = $this->check($art); ## We already have them if ($item) { $this->item[$item]["num"] += $num; return $item; } ## New article $item = $this->currentItem++; $this->item[$item]["art"] = $art; $this->item[$item]["num"] = $num; return $item; } The first item in cart has the ARRAY-INDEX = 0 (number). So "if ($item)" [expands to "if (0)"] FAILS for the first item in cart as if it's not in the cart! Suggestion: if ($item !== FALSE) // !== operator requires PHP >4 This problem may be in other functions too, please check this out! ---------------------------------------------------------------------- You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=403611&aid=496254&group_id=31885 |