in reply to Re: Duplicate items in cart do not appear
in thread Duplicate items in cart do not appear
And, then carry everything over to my Add Item subroutine, I receive Shopping Cart is Empty message.$clref = $dbh->prepare ("SELECT color FROM item WHERE prod_id = ".$ref +->{product_id}); $clref->execute(); while (my $color = $clref->fetchrow_hashref()) { push @{$ref->{color}}, $color->{color}; }
$clref = $dbh->prepare ("SELECT item_id, color FROM item WHERE prod_id + = ".$ref->{product_id}); $clref->execute(); while (my $color, $item_id = $clref->fetchrow_hashref() +) { push @{$ref->{color}, {$ref->{item_id}}, $color->{color +}, $item_id->{item_id}; }
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 item, catalog_pet WHER +E catalog_pet.product_id = item.prod_id AND catalog_pet.product_id = +?"); $sth->execute ($item_id); my $item_ref = $sth->fetchrow_hashref (); $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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Duplicate items in cart do not appear
by perrin (Chancellor) on Feb 24, 2003 at 18:42 UTC |