Hi Jasonk,
I modified my add_item subroutine from hashref to arrayref and three things are occurring:
(1) when I select the first color on my list I'm receiving the following message: Can't coerce an array into a hash.
(2) when I select an item of another color, my view cart only shows item_id, quantity, and color; the description and price is not carried foward.
(3) when I try to select the same item again with a different color; it's still overwriting placing the most recent choice into the cart and removing the previous choice.
Here is how my new add_item subroutine appears when I made your modification:
sub add_item
{
my ($dbh, $cart_ref, $item_id, $qty, $color) = @_;
# If the item isn't already in the cart, look it up from the datab
+ase
# and store it in the cart as a new entry with a quantity of zero.
if (!exists ($cart_ref->{$item_id}))
{
my $sth = $dbh->prepare ("SELECT * FROM catalog_pet
WHERE item_id = ?");
$sth->execute ($item_id);
my $item_ref = $sth->fetchrow_arrayref ();
$sth->finish ();
return if !defined ($item_ref); # this shouldn't happen...
$cart_ref->{$item_id} = {}; # create new entry, indexed by
+item ID
$cart_ref->{$item_id}->{description} = $item_ref->{description
+};
$cart_ref->{$item_id}->{price} = $item_ref->{price};
$cart_ref->{$item_id}->{qty} = 1;
}
$cart_ref->{$item_id}->{qty} = $qty;
$cart_ref->{$item_id}->{color} = $color;
}
Any other thoughts or ideas would be great!
Thanks
| [reply] [d/l] |