eShopping Cart 1.10
A simple method of doing shopping using ASP.
This project is a simple ASP shopping cart, using basic ASP techniques. It is intended for
users of the EarthPort or PriceTag e-commerce system, but is not dependent on either. It can
also utilise the ASPMail component to send the completed order to an e-mail sales address
before processing the credit card stuff. You can disable this, or change the code to work with
a different mail system. There are plenty of code snippets available to do this.
The system has 3 stages: the first is the actual products page, where all the products and
prices are listed. The second is the shopping cart, and the third is the checkout, where you
fill in you name and stuff and then the order is processed.
I have tested the cart with about 100 products, but I suppose there must be some kind of
usability limit once you get over 250 products, just in terms of trying to keep track of all the
codes and maintaining the variables and stuff. If you have that many products you need to
keep the information in a database, which makes the whole shopping cart exercise even more
terrifying. I have tried to simplify the process as much as possible by using the Products.xls
Also be aware that servers using IIS 3.0 will have a performance problem if the total size of
the ASP page (with its include files) exceeds 64k. If the server suddenly hits a performace
problem, it could be the size of the page. I haven‟t had the same problem with IIS 4.0 (yet).
The products page supplied is completely over-simplified. This is deliberate and you are
expected to use it as a basic template. There is no reason why you should only have one
product page, and one site this cart was intended for has a different page for every product.
Also, the page can be subdivided using the “NAME” tag in HTML, so that the buyer can
return to the same part of the page that they left.
Some of the customising can be done simply by changing variables in the global.inc and
prices.inc pages. These are covered in more detail later, but the most obvious variables to set
up are strMerchant and strLogo, as these are visible from the opening page. There is a
spreadsheet that you can use to help simplify the process of updating the data.
The basic page starts with an opening logo graphic and H1 bold heading:
<title><%=strMerchant %> Products</title>
<meta name="keywords" content="keywords go here">
<body><%=strFontBody & strLogo %><br clear="right">
<h1 align="center"><%=strFont & "<b>" & strMerchant %>
<!--- All the product info goes here -- START --->
<! ------ All the product info goes here -- END --->
If you are new to ASP, the include statement shown above just “slots in” the contents of the
file before any of the code is executed. So let‟s look at the products.inc file, which is
generated by the products.xls spreadsheet:
<!-- Product: AA -- START -->
Some basic explanation of the <A NAME="Subs"> tag is instructive at this point. You can
divide the products page into sections, and then allow the user to return to the start of the
EShopping Cart Implementation Guide Page 1 of 7
section once they have added items to the cart. Obviously, you need to replace the word
“Subs” with something more appropriate for your product or product group.
Now let‟s consider product AA. The product listing looks like this:
<!-- Product: AA -- START -->
<h2 align="center"><%=strFont %>AA</font></h2>
<p><%=strFontBody %><b>Product:</b> <%=strAA %></font></p>
<% if EarthPort then %><a href="#EP"><%=strElogo %></a> <%
end if %>
<% if PriceTag then %><a href="#PT"><%=strTlogo %></a> <% end
<A HREF="<%=BuyURL(strAA, curAAvat, "AA", sngAAmass,
<%=CentsPrice(curAAvat) %></a> including VAT* </font></p>
<!-- Product: AA -- END -->
Replace the “AA” text with the product title, so that it can appear in the <H2> tag. Also, you
can use the short description of the product, by utilising the strAA variable. Finally, you can
show the price of the product (curAAvat), and have a purchase link to the cart, using the
BuyURL function. Note that the last parameter is the return URL, constructed of the page
name and the section. If you changed the word “Subs” in the name tag, make sure you change
it in the BuyURL parameter as well.
The values of strAA, curAAvat, sngAAmass and curAAprice are set in the prices.inc file, so
that one price change will be reflected immediately wherever the price is quoted. This is
useful for special offers as well as general price adjustments. You can make these changes
manually, but the simplest way is by using the spreadsheet.
This is where you build a sales order, and allow the user to calculate prices, add to the
shopping cart, and continue shopping. This page is re-entered several times. The first time it is
called, the parameters passed are formatted in the BuyURL style, so you don‟t have to have
form buttons on your product pages. A typical URL would be:
The information is passed to the cart.asp page, where it is passed to the required variables
and shown as a small table in a form. The user can add the default quantity (1) to the shopping
cart, or change the quantity and then calculate the price and mass before adding it to the cart.
Once it is added to the cart, the information is stored in a session variable in the form:
<CRLF> CODE %% QTY $$ DESCRIPTION ## Mass ;; COST :: SUBTOTAL <CRLF>
i.e. “ AA%%1$$Product Description##100;;123.45::123.45”
The code is 6 characters long, and the description is 35 characters long, although you can
change these parameters if your needs are different. Just remember that the lines can get quite
wide and the e-mail message will wrap. There is a CR LF combination either side of the line,
to prevent the leading spaces from being trimmed off.
When a new line is added, the product code is searched for, and if found in the order string,
the old line is removed and replaced with the new one, and the total is recalculated.
The reference number for the cart is taken from the visitor count number. This is handled in
the global.asa file. If your ISP can‟t get the rights correct for the visitors.txt file (it has been
known to happen that ISPs are completely clueless about their own servers), then modify the
global.asa file to generate a new numbering series whenever the server is restarted. Provided
the server doesn‟t get rebooted more than once per hour it should work ok.
EShopping Cart Implementation Guide Page 2 of 7
If the user decides to clear out the shopping cart, the clear.asp page does this, and goes to the
start of the “products.asp” page. Most likely the user will either click on “Continue
shopping”, which will return to the “products.asp#Section” supplied URL, or the
“Send the order” link, which will then proceed to the checkout page.
This is where you take down the customer details and process the order. Again, the page is
designed to be run more than once. The first time all the contact details are blank, but once the
user has entered all the valid details then the details are displayed one final time so that the
order can be confirmed, at which point the ASPMail component is used to mail the complete
order to the sales e-mail address, and cc‟ing a copy to the person placing the order. The mail
message causes Microsoft Outlook to send one of those annoying little “Message Read” e-
mails, but they are useful in this case to determine that (a) the sales guys read the mail, and
(b) that the buyer‟s e-mail address is working. If the “message read” mail bounces, then you
know there is something wrong.
The testing of input information is not particularly rigorous. For example, there is nothing to
stop the user from putting letters in the phone or fax fields, and so on. But the simple basic
testing is done, to ensure that first name, surname, address and e-mail are included.
The Checkout page can be called with one of 3 options: mail, wallet or card, which process
the required ASPMail, EarthPort or PriceTag options, respectively.
An optional part is the “Dealer Page”. This page allows selected people to log on, and to see
the entire product catalogue on a single form. They can then order as many items as may be
required, and send it to the merchant, without the dealer having to wade through the product
pages and wait for graphics to load.
The opening page is called dealer.asp and it requires the support page, names.inc, where the
login names and other details of the approved dealers are kept.
'<-- Dealer START -->
case ".demo." ' // Login name between ..
strDealerName = "Demo Dealer" '// Dealer Name
strDealerMail = "email@example.com" '// Dealer e-mail
sngDiscount = 10 '// % Discount
fLogon = False
'<-- Dealer END -->
That‟s basically it. But don‟t edit this file manually. Use the Products.xls spreadsheet to do
the work for you. The reason for this is that there are lines of code required by the dealer.asp
and order.asp pages, for each product in the catalogue. These lines are generated by the
spreadsheet as well.
Why no databases on the web site?
There are two reasons: security, and complexity. Personally, I don‟t feel comfortable with all
my data sitting on a server which the general public can hack into. I am pretty sure that if the
ASP code is working at all then it isn‟t possible to download the .asp and .inc files from your
browser. This can only happen via FTP, so make sure your FTP access is properly secured.
But there is nothing stopping me from seeing an error message about a data file and then
using the browser to download the contents of the data file to your hard drive. If that file
contains unencrypted credit card information you are in big trouble!
The other reason is complexity: not only do you have to try to get all the data connections
correct on a remote machine, but if the ISP doesn‟t have a clue about Windows NT (we won‟t
mention names here, suffice it to say that to get them to install an ASP component on their
server took 6 weeks of ranting and raving) then they probably don‟t have the correct version
EShopping Cart Implementation Guide Page 3 of 7
of the Microsoft Data Access components (MDAC) loaded anyway. And some hosting fees
cost more if there is a database involved. It‟s just too easy for databases to go wrong. My own
hobby web site has run largely uneventfully for 3 years without a database on the server. I
keep the database on my own computer, and generate the required files, knowing that the data
is safe and sound and off-line.
Branding information in global.inc
The file global.inc contains a large proportion of all the branding information needed to make
the shopping cart look like part of your site.
' Most of the branding is done here
strCurrency = chr(128) '// Transaction currency €
strMerchant = "Merchant Name" '// Seller's name
strURL = "http://www.merchantname.com/"
strMPhone = "(011) 555-1234" '// Seller's Phone Number
strMFax = "(011) 555-1235" '// Seller's Fax Number
strSMTP = "mail.uskonet.com"
ASPMail = True
strMerchantMail = "firstname.lastname@example.org"
strImages = "art/"
strLogo = "<img src=""" & strImages & "merchantname.gif""
border=""0"" width=""180"" height=""50"" align=""right"">"
The currency symbol shown here is the Euro, but you could just as easily use “$” or “R” or
whatever, provided it is a single character. Substitute the words “Merchant Name” with the
name of the supplier, and make similar changes to all occurrences of “merchantname” as
shown in bold above. You will also need to set the correct dimensions for your logo.
The strImages variable requires a little more explanation. The artwork supplied for this
project is stored in a directory called “art”. If you want to use a different directory, then
change the name to "images/" or "../images/" or whatever is appropriate for your site.
The strSMTP variable is the name of the SMTP server that your ASP server is allowed to use
for sending mail. Make sure you test this using a variety of e-mail addresses. You can set
ASPMail to False if you don‟t require e-mail delivery of the order.
Make sure you specify the correct height and width values for the gif file you use for your
logo, or it will start looking a bit distorted. You should also consider editing the “alt” property
There is more branding information in bank.inc, which you should modify if you intent to
do request direct bank deposits.
The use of the EarthPort features is not particularly advanced. But the essential aspects of the
EarthPort requirements are met. You must have signed up as merchant, and make sure your
merchant wallet number is supplied in global.inc’s strMID variable.
' Ordering URL for Earthport.com
strURLpage = "https://www.Earthport.com/purchase.asp?"
strURLfail = "http://www.merchantname.com/fail.asp"
strURLpass = "http://www.merchantname.com/success.asp"
strMID = "&mid=3300013600214" '// Merchant ID from EarthPort
strOther = "&reqf=sapmpn&reqr1=email&reqr2=fullname"
strElogo = "<img src=""" & strImages & "p.gif""
alt=""Earthport.com"" border=""0"" width=""11"" height=""14"">"
EarthPort = True
EShopping Cart Implementation Guide Page 4 of 7
Some of these concepts are best explained by the EarthPort Implementation Guide. But the
fail.asp and success.asp files need to have the correct URL, so make sure you follow the
guidelines provided. The last value determines whether to enable the EarthPort messages,
URLs, icons, and so on. Set it to True while you are testing, and then set it to false when you
“Go Live” until the correct due diligence procedures are completed.
If you don‟t plan on using any of the EarthPort features, just set the EarthPort variable to
False. Make sure you set the ASPMail or PriceTag variables to True if you do this, or
the order will be forgotten! While it is theoretically possible to use both EarthPort and
PriceTag at the same time, I can‟t see why you would want to.
PriceTag is a „super merchant‟ service: they take the credit card details on your behalf and
send you the order that has been received, as well as sending you the money. You don‟t have
to get a Credit Card Merchant account, which saves a major amount of admin and frustration
with the South African banks.
Send an e-mail to email@example.com and visit their web site. Set the PriceTag
variable to True and EarthPort to False. Get a merchant ID code from them and follow
the instructions in their testing process. Also set the return URL as shown below, or use
strURL which you already set, as done in global.inc
' PriceTag support: Visit http://www.pricetag.co.za
' or mail them to get their
' Technical Specs Document: firstname.lastname@example.org
strMerchantID = "TEST-0001" '// Must be supplied by pricetag.co.za
PriceTag = True
strTlogo = "<img src=""" & strImages & "t.gif""
alt=""PriceTag.co.za"" border=""0"" width=""24"" height=""21"">"
strURLreturn = "http://www.merchantname.com/return.asp"
Set up the products and prices and weights in the spreadsheet, and you‟re nearly there!
The support/test files
Once of the most useful is srvvar.asp. This file displays information about your server, and
checking the rights for the visitors.txt file. Make sure that srvvar.asp goes into the same
directory as global.asa, preferably the “root” directory of the site.
There is also form.asp, which will display the information sent to it by a “POST” instruction
in a form. Use this if you intend to modify the code supplied to work with a different e-
The site.inc file is only used at http://www.support.co.za/cart/ to allow you to
change the EarthPort, PriceTag and ASPMail options and see how it changes the site.
Write to me if you want to see the code in this file. You could just as easily remove all the
references to site.inc in your project by deleting the lines that read:
EShopping Cart Implementation Guide Page 5 of 7
Quick Tutorial: Setting Up A New Product
Because the number of products is likely to grow, there is a spreadsheet (with macros) to help
you manage your product codes and prices. Double-click on products.xls (and Enable
Macros if asked by Excel). You will see a simple spreadsheet with the basic product
information required. Try adding in a few products, for example
Qty: 0 (this should always be 0 unless you require the dealers to order a specific amount)
Product: Hard Disk Drive
Price Ex Vat: 1250
Copy and paste the VAT formula in column E
Product Page: products.asp#HDD
Now make sure the contents of cell J1 reflect the path of where you want to put the generated
files. This should be the same directory as all the other files you extracted from freecart.zip.
Press ctrl-j and find the files that it creates/updates. They are:
You can examine the code that is generated if you are curious to see how it all fits together.
Now you are ready to upload all the files to your server. If you already have a global.asa file
in place on your web site, modify it to include the code supplied, or something else may go
wrong with your web site.
Integrating with FrontPage 2000
There is no compelling reason why you should use FrontPage instead of any other web site
creation tool, other than perhaps that it knows what to do with the <% and %> tags most of
the time. But you could just as easily upload all the supplied ASP pages, and get your browser
to display the products.asp page, and then save the HTML code and copy and paste the
saved page snippets into your “real” product pages. Just make sure you put the names of the
real product pages in the spreadsheet, so the return URLs take the browser back to the correct
Important note: Do not try to edit these ASP pages using FrontPage 98 or older: they
usually mess up the formatting. I‟m not sure about other HTML editors. I prefer to use
Notepad in Windows (or EditPad from http://www.jgsoft.com/) and I suppose BBEdit on
the Macintosh will also do the trick.
EShopping Cart Implementation Guide Page 6 of 7
This „freeware‟ cart was written by Donn Edwards for use on a private web site, as well as
our own company web site www.support.co.za. If you find it useful, you are welcome to
adapt it as you see fit. I am always interested in hearing how you may have improved it. You
may not sell any part of this code. Please contact me at email@example.com with
comments, questions or for general discussion. Don‟t send me any lawyer‟s letters, other than
to offer me money. Some of the text is quite specific to South Africa, so make changes as you
see fit. The code supplied here is operational at http://www.support.co.za/cart/
EarthPort, PriceTag and ASPMail are trademarks of their respective companies, and this
project is done independently and apart from their endorsement.
EShopping Cart Implementation Guide Page 7 of 7