Bugs item #496254, was opened at 2001-12-23 21:22
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=403611&aid=496254&group_id=31885
Category: None
Group: None
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
>Assigned to: Richard Archer (richardarcher)
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!
----------------------------------------------------------------------
>Comment By: Richard Archer (richardarcher)
Date: 2002-04-26 22:46
Message:
Logged In: YES
user_id=279311
I can't replicate this bug.
The way cart works, the items in the cart should be numbered
from 1, not 0. I suspect the problematic installation of
cart has been mangled somehow.
The declaration:
var $currentItem = 1;
sets the array index of the first item to be added to the
cart. This is incremented for each additional item.
reset() resets this to 1.
set_item() and remove_item() never decrement this value, so
it should never become 0.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=403611&aid=496254&group_id=31885
|