This is untested but might work:
my ($cgi, $session) = @_;
# getting the cart's contents
my $vars;
$vars->{total_price} = 0;
foreach my $product ( @{$session->param('CART')} ) {
$product->{prod_subtotal} = $product->{price} * $product->{quantity};
$vars->{total_price} += $product->{prod_subtotal};
push @($vars->{cart_loop}), $product;
}
require GT::Template;
return GT::Template->parse('html.tmpl', $vars);
}
and your template:
<p>Here are your cart:</p>
<br><br>
<table>
<tr>
<td>Qty</td>
<td>Product</td>
<td>Unit Price</td>
<td>Product Subtotal</td>
</tr>
<%loop cart_loop%>
<tr>
<td><%quantity%></td>
<td><%name%></td>
<td><%price%></td>
<td><%prod_subtotal%></td>
</tr>
<%endloop%>
<tr>
<td colspan="3">Sub Total</td><td><%total_price%></td>
</tr>
</table>
<%else%>
<p>There are no items in your cart yet</p>
<%endif%>
Make sure you check out the pod for GT::Template. There's a *lot* you can do with it.
~Charlie
Code:
sub display_cart { my ($cgi, $session) = @_;
# getting the cart's contents
my $vars;
$vars->{total_price} = 0;
foreach my $product ( @{$session->param('CART')} ) {
$product->{prod_subtotal} = $product->{price} * $product->{quantity};
$vars->{total_price} += $product->{prod_subtotal};
push @($vars->{cart_loop}), $product;
}
require GT::Template;
return GT::Template->parse('html.tmpl', $vars);
}
and your template:
Code:
<%if cart_loop%> <p>Here are your cart:</p>
<br><br>
<table>
<tr>
<td>Qty</td>
<td>Product</td>
<td>Unit Price</td>
<td>Product Subtotal</td>
</tr>
<%loop cart_loop%>
<tr>
<td><%quantity%></td>
<td><%name%></td>
<td><%price%></td>
<td><%prod_subtotal%></td>
</tr>
<%endloop%>
<tr>
<td colspan="3">Sub Total</td><td><%total_price%></td>
</tr>
</table>
<%else%>
<p>There are no items in your cart yet</p>
<%endif%>
Make sure you check out the pod for GT::Template. There's a *lot* you can do with it.
~Charlie