Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

shopping cart question. 1

Status
Not open for further replies.

perlcoder

Programmer
Jul 1, 2001
16
0
0
US
I have been trying to adapt a free shopping cart on the Web site I am building for a friend. Its configuration was very difficult, but between the original version and the new version, I was able to make quite a few improvements, like the creation of a "Thank you" Web page at the end of a business transaction.

Technically, I should send you the entire program through the e-mail so that you can see it for yourself. Unfortunately, I cannot add an attachment to this message. Don't be alarmed, this is not a huge programming project, the code works but has some flaws, and I need an expert like yourself to give some advice for one particular problem only.

To have a better understanding of my problem, you may have to download the original free shopping cart at: and then hit the download link.

You will then see 4 folders:

cgi-bin, lucys, datafiles, and misc. cgi-bin and lucys are the folders of interest for my problem.

cgi-bin contains 4 files: admin.cgi, checkout.cgi, orders.cgi and setup.pl

lucys has many HTML files but only one is of interest: index.html which codes for the entry point of the shopping cart and is written in JavaScript.

Now after looking at the original shopping cart (Demo 1 or Lucy's shopping cart), please go to the Web site I have built, at the shopping cart Web page at:


Once in the page, after placing a fake order, then checking out, you will reach a Check Out page with "Order information", "Billing information", Shipping information" and "Credit card information".

Notice the section called "Order information" where you can see the shopping cart content in a tabulated form, and below it a subtotal, sales tax, shipping and a total.

After filling out the fields with bogus information, enter in the "Credit card information", 16 "zeros" then hit purchase, there you will reach my famous "Thank you" Web page.

You will then notice some missing items, such as all the information in the "Order information" section and in the sentence above it "Your order number is:" a number with 5 digits, which should look like this if your order number is for instance 94: 00094.

To make this "Thank you" page, I modified one file in cgi-bin called "orders.cgi." In it I replaced the last line of the code:

print 'Location:'.$thankspage.'?'.$counttext."\n\n";

with the code below to generate a new HTML page, buyers can print out after ordering.

# CODE:

print "Content-type: text/html\n\n";
print << &quot;_FIN_&quot;;
<HTML>
<HEAD>
<LINK REL=&quot;stylesheet&quot; HREF=&quot;style.css&quot; TYPE=&quot;text/css&quot;>
<TITLE></TITLE> <SCRIPT>
function writesearch(){
var orderno=document.location.search;
orderno=orderno.substr(1);
document.write(&quot;<b>&quot;+orderno+&quot;</b>&quot;);
}
function clearorder(){
parent.cartcookie.delcookie();
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR=&quot;#FFF7DE&quot; TEXT=&quot;#663333&quot; LINK=&quot;#339900&quot; VLINK=&quot;#9900FF&quot;
ALINK=&quot;#FF3333&quot;>
<H2 ALIGN=&quot;CENTER&quot;>Souzao Enterprises online store</H2> <BR><BR>
<DIV ALIGN=&quot;center&quot;>
<H3>Thank You</H3></DIV>
<P>Thank you for shopping at the Souzao Enterprises online store. We
appreciate your business.</P>
<P>Your order number is:&nbsp;&nbsp;<SCRIPT>writesearch();</SCRIPT></P>
<P>Please print and keep this number for future reference.</P><BR><BR>
<DIV ALIGN=&quot;center&quot;> <B>Order Information</B>
<FORM NAME=&quot;checkoutform&quot; METHOD=&quot;post&quot;
ACTION=&quot;<TABLE BORDER=&quot;1&quot; CELLPADDING=&quot;2&quot; CELLSPACING=&quot;0&quot;>
<TR>
<TH BGCOLOR=&quot;#FFCC66&quot;>Product Id</TH>
<TH BGCOLOR=&quot;#FFCC66&quot;>Product Name</TH>
<TH BGCOLOR=&quot;#FFCC66&quot;>Options</TH>
<TH BGCOLOR=&quot;#FFCC66&quot;>Price</TH>
<TH ALIGN=&quot;center&quot; BGCOLOR=&quot;#FFCC66&quot;>Quantity</TH>
<TH ALIGN=&quot;center&quot; BGCOLOR=&quot;#FFCC66&quot;>Item Total</TH>
</TR>
<TR VALIGN=&quot;top&quot;>
<TD>&nbsp;</TD>
<TD>&nbsp;</TD>
<TD>&nbsp;</TD>
<TD ALIGN=&quot;right&quot;>&nbsp;</TD>
<TD ALIGN=&quot;center&quot;>&nbsp;</TD>
<TD ALIGN=&quot;right&quot;>&nbsp;</TD>
</TR><INPUT TYPE=&quot;hidden&quot; NAME=&quot;o01Item&quot;
VALUE=&quot;²r;²c;²r;&quot;>
</TABLE><BR>
<TABLE BORDER=&quot;0&quot; CELLPADDING=&quot;2&quot; CELLSPACING=&quot;1&quot;>
<TR VALIGN=&quot;top&quot;>
<TD>Subtotal</TD>
<TD ALIGN=&quot;right&quot;>&nbsp;</TD>
</TR><INPUT TYPE=&quot;hidden&quot; NAME=&quot;s01Subtotal&quot;
VALUE=&quot;Subtotal²r;&quot;>
<TR VALIGN=&quot;top&quot;>
<TD>Sales Tax</TD>
<TD ALIGN=&quot;right&quot;>&nbsp;</TD>
</TR><INPUT TYPE=&quot;hidden&quot; NAME=&quot;s02Salestax&quot; VALUE=&quot;Sales Tax²r;&quot;>
<TR VALIGN=&quot;top&quot;>
<TD>Shipping</TD>
<TD ALIGN=&quot;right&quot;>&nbsp;</TD>
</TR><INPUT TYPE=&quot;hidden&quot; NAME=&quot;s03Shipping&quot;
VALUE=&quot;Shipping²r;&quot;>

<TR VALIGN=&quot;top&quot;>
<TD>Total</TD>
<TD ALIGN=&quot;right&quot;>&nbsp;</TD>
</TR><INPUT TYPE=&quot;hidden&quot; NAME=&quot;s03Total&quot; VALUE=&quot;Total²r;&quot;>
</TABLE> <HR></FORM></DIV><BR><BR>
<TABLE BORDER=&quot;1&quot; CELLPADDING=&quot;10&quot; CELLSPACING=&quot;0&quot; ALIGN=&quot;CENTER&quot;>
<TR VALIGN=&quot;MIDDLE&quot;>
<TD BGCOLOR=&quot;#FFCC66&quot; VALIGN=&quot;MIDDLE&quot; ALIGN=&quot;CENTER&quot;>
<P><B>Bill to:</B></P></TD>
<TD BGCOLOR=&quot;#FFCC66&quot; VALIGN=&quot;MIDDLE&quot; ALIGN=&quot;CENTER&quot;>
<P><B>Ship to:</B></P></TD>
</TR>
<TR>
<TD><B>First Name:</B> $FORM{'a01FirstName'}<BR> <B>Last Name:</B>
$FORM{'a03LastName'}<BR> <B>Address1:</B> $FORM{'a04Address1'}<BR>
<B>Address2:</B> $FORM{'a05Address2'}<BR> <B>City:</B> $FORM{'a06City'}<BR>
<B>State/Province (US or Canada):</B> $FORM{'a07USState'}<BR> <B>State/Province
(outside US or Canada):</B> $FORM{'a08State'}<BR> <B>Zip/Postal Code:</B>
$FORM{'a09PostalCode'}<BR> <B>Country:</B> $FORM{'a10Country'}<BR></TD>
<TD><B>First Name:</B> $FORM{'b01FirstName'}<BR> <B>Last Name:</B>
$FORM{'b03LastName'}<BR> <B>Address1:</B> $FORM{'b04Address1'}<BR>
<B>Address2:</B> $FORM{'b05Address2'}<BR> <B>City:</B> $FORM{'b06City'}<BR>
<B>State/Province (US or Canada):</B> $FORM{'b07USState'}<BR> <B>State/Province
(outside US or Canada):</B> $FORM{'b08State'}<BR> <B>Zip/Postal Code:</B>
$FORM{'b09PostalCode'}<BR> <B>Country:</B> $FORM{'b10Country'}<BR></TD>
</TR>
<TR>
<TD><B>Coupon:</B> $FORM{'a15Coupon'}<BR></TD>
<TD><B>Insurance:</B> $FORM{'a16Insurance'}<BR></TD>
</TR>
<TR>
<TD COLSPAN=&quot;2&quot;> <B>Information package:</B>
$FORM{'a17Informationpackage'}<BR><BR><B>Type of information package:</B>
$FORM{'a18Typeofinformation package'}<BR></TD>
</TR>
</TABLE> <BR><BR>
<P ALIGN=&quot;CENTER&quot;><A
HREF=&quot; Shopping</A>
&nbsp;&nbsp;&nbsp;&nbsp;<A
HREF=&quot; TARGET=&quot;_top&quot;>Site
Home</A></P>
_FIN_
print&quot;<br><br>&quot;;
print'</body></HTML>';

# END OF CODE

Notice that the shopping cart content is empty and so are the values next to subtotal, sales tax, shipping and total. I was not able to transfer them with $FORM{'value'}, because I have a hard time finding the exact name of these values in the file called index.html (lucys folder). For instance in index.html in lines 447 - 451 (if you have a numbering system in your editor) or after 3/4 of the beginning of the code, I see the following values:

's01Subtotal'
's02Salestax'
's03Shipping'
's03Total'

but once introduced in the $FORM{'values'}, they don't give the values you chose in the checkout page. As for the table of content, I don't know what values to pick.

Likewise, in the &quot;Thank you&quot; page, there should be an order number based on the code in orders.cgi.

printf ORDERS (&quot;%05d&quot;, $count);

AND

$counttext = sprintf (&quot;%05d&quot;, $count);

But it doesn't show up on the &quot;Thank you&quot; page, why?

I am hope that my question was clear. Thank you for your attention to this message.
 
well, this is quite the task you've given, but i'll give it a shot, maybe make some headway.

now, i didn't actually look at any of the code you're playing with, so to help you debug this, it might help to do this at some or many points in your printing of the various pages:[tt]
print &quot;<h3>Debuging info</h3>\n&quot;;
foreach my $key (keys %FORM)
{
print &quot;$key = ${FORM{$key}}<br>\n&quot;;
}[/tt]

just to show you the contents of this hash (which you seemed to express doubts about).

now for a quick lesson in how web pages like this work, just to make sure we're on the same level. data needs to be shared by multiple pages during this checkout. to do this, the various pages will have html forms with all of the data included in it (as either visible or hidden input fields), so that when the user presses the button at the bottom, all that information will be passed along to the next script to be verified/processed/whatever. this data then has to be read by the next script (through various environmental variables, depending on the method of data transfer) and put into some sort of data structure before it is usable.

so, in the script you have to print up the thank you page, you're neither getting the data contained in the %FORM of the other pages, nor parsing it out of the request. &quot;$thankspage.'?'.$counttext&quot; will pass on the $counttext value, which will then be available for use via the environmental variable $ENV{QUERY_STRING}, however, you have alot more data than just that to pass through. beyond just $counttext, you need to get (or post) the entire FORM hash into the next script. you can either encode it similarly in a query string (get), or you can pass the information in by posting it (with a form). then you'll need to be sure to capture that information and split it apart into a hash again to be used by the thank you page.

i hope the gives you a better place to work off of. if you don't understand any of this, or if you do understand it but still have problems, please ask more questions. sorry i didn't have time to d-l the scripts and look at them myself.

stillflame &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
Greetings Perlcoder:

This will be a short message since I really don't have the time at present to read and absorb all the code that you submitted.

My first thought following a visit to your site is that most of your code is located in the CGI bin. IMHO, that is the root (no pun) of your problem. Your welcoming (page) script is loading from the bin, exiting the bin to confirm a purchase, hanging the popup until an unsecure message is confirmed, and then reentering the bin to perform another task time and time again.

What is happening is that you are losing state.

All you really need in the bin are your secure PERL/CGI scripts. All the other files should be on root or a sub directory root outside the bin. That way, maintaining state is more easily controlled including your thank you page.

I hope this suggestion doesn't give you coding jitters after all the work you completed.

CSC


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top