Building a Pizza: Completing the Order
June 14, 1999
sub complete_order()
#checkout order
{ print $cgiobject->header;
print $cgiobject->
start_html(-title=>'Thank you from
Build-a-Pizza',
-bgcolor=>'white');
$invoice= "<H2>Thank you for your pizza order!</H2>".
"<HR>Deliveries should arrive in 30-45 minutes. ".
"Pickup orders please arrive in about 20 minutes.<BR>".
"The following order has been sent to the kitchen:<BR>";
if ($deliver eq "deliver")
{ $invoice.="<B>Delivery</B> " }
else
{ $invoice.="<B>Pickup</B> " }
$invoice.="Order for: $name<br>";
if ($deliver eq "deliver")
{ $invoice.="Delivery to: $address<br>" }
$invoice.="Order Description: ".
"<br>A <B>$size</B> ".
"pizza with the ".
"following toppings:<br>";
@allToppings=$cgiobject->param("order_toppings");
$invoice.="<B>".join(",",@allToppings)."</B>";
$invoice.="<BR>TOTAL DUE: ".sprintf("%.2f",&calcTotal());
print $invoice;
##here would be code to send invoice kitchen
##such as by way of email
}
When the user clicks "Finish Order" we
move to the virtual checkout, as represented by the
complete_order
subroutine. This routine essentially constructs an
invoice, assigned to $invoice, containing the information
gathered from the submitted form fields. Once
constructed, the invoice is output to the visitor's browser
and might look something like:
Of course, the complete_order subroutine as shown
only outputs the invoice to the customer's browser
-- ideally the invoice should also be sent to the pizza
kitchen! One possibility would be to add some Perl code
which e-mails the invoice to a special e-mail address,
always monitored at the pizza parlor. We've left out this
code for now because there is no single "right"
way to send an e-mail message from a Perl program --
it depends on the operating system being served from and
its configuration.
Episode #9 of the Perl FAQ
addresses the question of sending an email message from
within Perl.
In our example, whatever the mechanics, we would want
to send the value of $invoice as the body of the message.
Building a Pizza: Calculating Cost
The Perl You Need to Know
Building a Pizza: Updating the Order
|