Yes, I'm aware of that. What I need to do is store the entries into the cart indexed by item_id, which distinguishes a product from one color to another.
When I try to bring in item_id with this statement of code:
$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};
}
And, then carry everything over to my Add Item subroutine, I receive Shopping Cart is Empty message.
Now, here is what I did to the code to try to bring in the item_id and which later produces an empty shopping cart message.
$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};
}
I'm trying to create a $ref->{item_id} so it is the same as all the other variables. Then, I'm trying to pass the $ref->{item_id} to the add_item subroutine.
It is quite apparent that I'm goofing up somewhere. I just don't know where.
Here's also what I've done to the add_item subroutine...
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;
}
You can see that I'm trying to store the cart entries by item_id. This attempt of coding produces an empty shopping cart message.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.