$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 database
# 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 WHERE 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;
}