473,554 Members | 2,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help with using shopping cart totals

hi i have a basic asp page that acts as an online bookstore. on my cart
page i am having trouble generating 3 numbers; a subtotal, a shipping
total, and a final price. here is my code

i would like it to work properly so that a record count counts through
all the books and genertates these numbers. watch out for line breaks

<%@ Language=VBScri pt %>
<% Option Explicit %>
<!--#include file="DatabaseC onnect.asp"-->
<!--#include virtual="06wint er/levini/database/adovbs.inc"-->
<html>
<head><title>Sh opping Cart</title>
<link rel="stylesheet " href="BookStore .css" type="text/css">
</head>
<table>

<!-- Header SSI starts here-->
<!--#include file="header.ht ml"-->
<!-- Header SSI ends here-->
<!-- Author SSI begins here-->
<!--#include file="ListAutho rs.asp"-->
<!-- Author SSI ends here-->
<%
'This shopping cart uses a cookie named "ShoppingCa rt"
'to store the ISBNs of the items in the cart.
'The cookie puts each ISBN value into a separate key named ISBN1,
ISBN2, etc.
'The current number of items in the cart is stored in a key named
"ItemCount"

dim ISBN, iItemCount, iItem, iCount, bFound, curPrice, curDiscPrice,
strSQL, objRS, strTitle, dblPrice, dblShipping, dblFinalPrice,
dblTotalPrice

ISBN = trim(Request.Qu eryString("isbn "))

'sql statement for individual books
strSQL = "SELECT tblBookDescript ion.ISBN,
tblBookDescript ion.strTitle, tblBookDescript ion.strDescript ion,
tblBookDescript ion.strPublishe r, tblBookDescript ion.dblPrice,
tblAuthors.Auth orID " & _
"FROM tblAuthors INNER JOIN (tblBookDescrip tion INNER JOIN
tblAuthorsBooks ON tblBookDescript ion.ISBN = tblAuthorsBooks .ISBN) ON
tblAuthors.Auth orID = tblAuthorsBooks .AuthorID " & _
"WHERE (((tblBookDescr iption.ISBN)='" & ISBN & "')); "

'response.write ("strSQL = " & strSQL)
Set objRS = Server.CreateOb ject("ADODB.Rec ordset")

objRS.open strSQL, objConn
curPrice = FormatCurrency( objRS("dblPrice "))
curDiscPrice = FormatCurrency( (objRS("dblPric e")*.8))
dblPrice = (objRS("dblPric e"))

dblTotalPrice = dblTotalPrice + curDiscPrice

'dblShipping = 3.49 + (iItemCount - 1) * .99

dblFinalPrice = dblTotalPrice + dblShipping

'Initialize iItemCount with number of books in the cart
If request.cookies ("ShoppingCart" ).HasKeys then
iItemCount = request.cookies ("ShoppingCart" )("ItemCount" )
else
'No cookie yet
iItemCount = 0
end if

'Add items to cart
If Request("action ") = "add" and len(ISBN)>5 then
'add new item to ShoppingCart
iItemCount = iItemCount + 1
Response.cookie s("ShoppingCart ")("ISBN"&iItem Count) = ISBN
end if

'Delete items from Cart
If Request.QuerySt ring("action") = "del" and len(ISBN)>5 then
'find the isbn
bFound = "False"
iItem = 1
Do while NOT bFound and iItem <= iItemCount
If Request.Cookies ("ShoppingCart" )("ISBN"&iIte m) = ISBN then
bFound = "True"
else
iItem = iItem + 1
End If
Loop

If bFound then
'replace the deleted item with the item above it
iItemCount=iIte mCount - 1
For iCount = iItem to iItemCount
Response.Cookie s("ShoppingCart ")("ISBN" &iCount)= _
Request.Cookies ("ShoppingCart" )("ISBN"&iCount +1)
Next
else
Response.write "Error: Could not match ISBN to delete."
end if
End If

'Update iItemCount
Response.Cookie s("ShoppingCart ")("ItemCount") =iItemCount
Response.Cookie s("ShoppingCart ").Expires = Date + 30

'
*************** *************** *************** *************** *************** ********
' Thsi is the end of the cookie protion for the cart
' The Items are displayed under here
'
*************** *************** *************** *************** *************** ********

' list items in shopping cart
If iItemCount < 1 then
response.write "<center><f ont face='Comic Sans MS'
color='#FF0000' >" & _
"Your Shopping Cart is empty.</font><br><br>"
Else
%>
<div align="center">
<center>
<font face='Comic Sans MS' color='#FF0000' >You have <%
=iItemCount %>
book<% If iItemCount > 1 then response.write "s"%> in
your shopping cart.
</font><br><br>

<table border="0" cellpadding="5" cellspacing="0"
width="643">
<tr>
<td width="20" > &nbsp; </td>
<td width="256" ><font face="Comic Sans MS"
Book</font></td> <td align="center" width="66" ><font face="Comic Sans MS"Quantity</font></td> <td width="179" ><font face="Comic Sans MS"Price</font></td> <td width="62" ><font face="Comic Sans MS"Remove</font></td>

</tr>
<%
'List each item in cart
For iCount = 1 to iItemCount
ISBN =
Request.Cookies ("ShoppingCart" )("ISBN"&iCount )
%>

<tr>
<td valign="top" width="20" >1.</td>
<td valign="top" width="256">
<! Book Title, author, stock >
<a href="ProductPa ge.asp?isbn= <% =objRS("ISBN")% > ">
<% =objRS("strTitl e")%></a>
<br>
<font size="-1">
by <% =funListAuthors (objRS("ISBN")) %></a>
</font>
<br>
</td>
<td valign="top" align="center" width="66">1</td>
<td valign="top" width="179">
<! Price >
<FONT face=arial,verd ana,helvetica>< B>List Price:
<font color=#990000>< strike><% =dblPrice
%></strike></font><br>

<FONT face=arial,verd ana,helvetica>O ur Price:
<font color=#990000>< % =curDiscPrice %></font><br>

<FONT face=arial,verd ana,helvetica>Y ou Save:
<font color=#990000>< % =FormatCurrency ((dblPrice -
curDiscPrice)) %>(20%)</b></font><br><br>
</td>
<td valign="top" width="62" >
<a
href="ShoppingC art.asp?ISBN=<% =objRS("ISBN")% >&action=del" > Remove</a>
</td>
</tr>

<% Next
%> </table>
</center>
<%End If
%>
<tr>
<td></td><td></td><td></td>
<td>
<FONT face=arial,verd ana,helvetica>
<table border="0" cellpadding="0" cellspacing="0"
width="150" >
<tr>

------------------------------------------------------problem area
<td width="75">Sub-Total:</td>
<td width="75"><p align="right">$ 152.00</td>
</tr>

<tr>
<td width="75">Ship ping*:</td>
<td width="75"><p align="right">< % =dblShipping
%></td>
</tr>
<tr>
<td width="75">Tota l:</td>
<td width="75"><p align="right">< %
=dblFinalPrice% ></td>
</tr>
------------------------------------------------------------------------------------------

</table>
</td>
</tr>
</table>
</center>
</div>

</table>
<br>
<div align="center">
<center>
<table border="0" cellpadding="5" cellspacing="0" width="400"
bgcolor="#99CCF F">
<tr>
<td><a href="default.a sp"><img border="0"
src="/06Winter/levini/images/continue-shopping.gif" width="121"
height="19"></a><br>
</td>
<td>
<p align="right">< a href="checkout. asp"><img border="0"
src="/06Winter/levini/images/proceed-to-checkout.gif" width="183"
height="31"></a>
</td>
</tr>
</table>

<table border="0" cellpadding="5" cellspacing="0" width="400">
<tr>

-------------------------------------------------shipping guidlines
<td> <br><p align=center> Shipping is $3.49 for the first book
and $.99 for each additional book. To assure reliable delivery and
to keep your costs low we send all books via UPS ground.
------------------------------------------------------------------------------------------------

</td>
</tr>
</table>
</body>
</html>
i know cookies isnt an ideal way to do it but i dont really know how to
do it with a SQL statement any help for any of this would be great.
thank you

isaac

Feb 24 '06 #1
7 2621

isaac2004 wrote:
hi i have a basic asp page that acts as an online bookstore. on my cart
page i am having trouble generating 3 numbers; a subtotal, a shipping
total, and a final price. here is my code

i would like it to work properly so that a record count counts through
all the books and genertates these numbers. watch out for line breaks

<%@ Language=VBScri pt %>
<% Option Explicit %>
<!--#include file="DatabaseC onnect.asp"-->
<!--#include virtual="06wint er/levini/database/adovbs.inc"-->
<html>
<head><title>Sh opping Cart</title>
<link rel="stylesheet " href="BookStore .css" type="text/css">
</head>
<table>

<!-- Header SSI starts here-->
<!--#include file="header.ht ml"-->
<!-- Header SSI ends here-->
<!-- Author SSI begins here-->
<!--#include file="ListAutho rs.asp"-->
<!-- Author SSI ends here-->
<%
'This shopping cart uses a cookie named "ShoppingCa rt"
'to store the ISBNs of the items in the cart.
'The cookie puts each ISBN value into a separate key named ISBN1,
ISBN2, etc.
'The current number of items in the cart is stored in a key named
"ItemCount"

dim ISBN, iItemCount, iItem, iCount, bFound, curPrice, curDiscPrice,
strSQL, objRS, strTitle, dblPrice, dblShipping, dblFinalPrice,
dblTotalPrice

ISBN = trim(Request.Qu eryString("isbn "))

'sql statement for individual books
strSQL = "SELECT tblBookDescript ion.ISBN,
tblBookDescript ion.strTitle, tblBookDescript ion.strDescript ion,
tblBookDescript ion.strPublishe r, tblBookDescript ion.dblPrice,
tblAuthors.Auth orID " & _
"FROM tblAuthors INNER JOIN (tblBookDescrip tion INNER JOIN
tblAuthorsBooks ON tblBookDescript ion.ISBN = tblAuthorsBooks .ISBN) ON
tblAuthors.Auth orID = tblAuthorsBooks .AuthorID " & _
"WHERE (((tblBookDescr iption.ISBN)='" & ISBN & "')); "

'response.write ("strSQL = " & strSQL)
Set objRS = Server.CreateOb ject("ADODB.Rec ordset")

objRS.open strSQL, objConn
curPrice = FormatCurrency( objRS("dblPrice "))
curDiscPrice = FormatCurrency( (objRS("dblPric e")*.8))
dblPrice = (objRS("dblPric e"))

dblTotalPrice = dblTotalPrice + curDiscPrice

'dblShipping = 3.49 + (iItemCount - 1) * .99

dblFinalPrice = dblTotalPrice + dblShipping

'Initialize iItemCount with number of books in the cart
If request.cookies ("ShoppingCart" ).HasKeys then
iItemCount = request.cookies ("ShoppingCart" )("ItemCount" )
else
'No cookie yet
iItemCount = 0
end if

'Add items to cart
If Request("action ") = "add" and len(ISBN)>5 then
'add new item to ShoppingCart
iItemCount = iItemCount + 1
Response.cookie s("ShoppingCart ")("ISBN"&iItem Count) = ISBN
end if

'Delete items from Cart
If Request.QuerySt ring("action") = "del" and len(ISBN)>5 then
'find the isbn
bFound = "False"
iItem = 1
Do while NOT bFound and iItem <= iItemCount
If Request.Cookies ("ShoppingCart" )("ISBN"&iIte m) = ISBN then
bFound = "True"
else
iItem = iItem + 1
End If
Loop

If bFound then
'replace the deleted item with the item above it
iItemCount=iIte mCount - 1
For iCount = iItem to iItemCount
Response.Cookie s("ShoppingCart ")("ISBN" &iCount)= _
Request.Cookies ("ShoppingCart" )("ISBN"&iCount +1)
Next
else
Response.write "Error: Could not match ISBN to delete."
end if
End If

'Update iItemCount
Response.Cookie s("ShoppingCart ")("ItemCount") =iItemCount
Response.Cookie s("ShoppingCart ").Expires = Date + 30

'
*************** *************** *************** *************** *************** ********
' Thsi is the end of the cookie protion for the cart
' The Items are displayed under here
'
*************** *************** *************** *************** *************** ********

' list items in shopping cart
If iItemCount < 1 then
response.write "<center><f ont face='Comic Sans MS'
color='#FF0000' >" & _
"Your Shopping Cart is empty.</font><br><br>"
Else
%>
<div align="center">
<center>
<font face='Comic Sans MS' color='#FF0000' >You have <%
=iItemCount %>
book<% If iItemCount > 1 then response.write "s"%> in
your shopping cart.
</font><br><br>

<table border="0" cellpadding="5" cellspacing="0"
width="643">
<tr>
<td width="20" > &nbsp; </td>
<td width="256" ><font face="Comic Sans MS"
Book</font></td>

<td align="center" width="66" ><font face="Comic Sans MS"
Quantity</font></td>

<td width="179" ><font face="Comic Sans MS"
Price</font></td>

<td width="62" ><font face="Comic Sans MS"
Remove</font></td>

</tr>
<%
'List each item in cart
For iCount = 1 to iItemCount
ISBN =
Request.Cookies ("ShoppingCart" )("ISBN"&iCount )
%>

<tr>
<td valign="top" width="20" >1.</td>
<td valign="top" width="256">
<! Book Title, author, stock >
<a href="ProductPa ge.asp?isbn= <% =objRS("ISBN")% > ">
<% =objRS("strTitl e")%></a>
<br>
<font size="-1">
by <% =funListAuthors (objRS("ISBN")) %></a>
</font>
<br>
</td>
<td valign="top" align="center" width="66">1</td>
<td valign="top" width="179">
<! Price >
<FONT face=arial,verd ana,helvetica>< B>List Price:
<font color=#990000>< strike><% =dblPrice
%></strike></font><br>

<FONT face=arial,verd ana,helvetica>O ur Price:
<font color=#990000>< % =curDiscPrice %></font><br>

<FONT face=arial,verd ana,helvetica>Y ou Save:
<font color=#990000>< % =FormatCurrency ((dblPrice -
curDiscPrice)) %>(20%)</b></font><br><br>
</td>
<td valign="top" width="62" >
<a
href="ShoppingC art.asp?ISBN=<% =objRS("ISBN")% >&action=del" > Remove</a>
</td>
</tr>

<% Next
%> </table>
</center>
<%End If
%>
<tr>
<td></td><td></td><td></td>
<td>
<FONT face=arial,verd ana,helvetica>
<table border="0" cellpadding="0" cellspacing="0"
width="150" >
<tr>

------------------------------------------------------problem area
<td width="75">Sub-Total:</td>
<td width="75"><p align="right">$ 152.00</td>
</tr>

<tr>
<td width="75">Ship ping*:</td>
<td width="75"><p align="right">< % =dblShipping
%></td>
</tr>
<tr>
<td width="75">Tota l:</td>
<td width="75"><p align="right">< %
=dblFinalPrice% ></td>
</tr>
------------------------------------------------------------------------------------------

</table>
</td>
</tr>
</table>
</center>
</div>

</table>
<br>
<div align="center">
<center>
<table border="0" cellpadding="5" cellspacing="0" width="400"
bgcolor="#99CCF F">
<tr>
<td><a href="default.a sp"><img border="0"
src="/06Winter/levini/images/continue-shopping.gif" width="121"
height="19"></a><br>
</td>
<td>
<p align="right">< a href="checkout. asp"><img border="0"
src="/06Winter/levini/images/proceed-to-checkout.gif" width="183"
height="31"></a>
</td>
</tr>
</table>

<table border="0" cellpadding="5" cellspacing="0" width="400">
<tr>

-------------------------------------------------shipping guidlines
<td> <br><p align=center> Shipping is $3.49 for the first book
and $.99 for each additional book. To assure reliable delivery and
to keep your costs low we send all books via UPS ground.
------------------------------------------------------------------------------------------------

</td>
</tr>
</table>
</body>
</html>
i know cookies isnt an ideal way to do it but i dont really know how to
do it with a SQL statement any help for any of this would be great.
thank you

isaac


For each title that's added to the cart, store the price in another key
in the cookie ("ISBNPrice" & iCount). Then loop through them, adding
them as you go to obtain the subtotal:

dblSubTotal = 0
for i = 1 to iItemCount
dblSubTotal = dblSubTotal +
Request.Cookies ("ShoppingCart" )("ISBNPrice"&i Count)
next

You shipping price is as follows:

dblShipping = 3.49 + ((iItemCount - 1) * .99)

and your total price is dblShipping + dblSubTotal.

But you are right - cookies are not the ideal way to manage shopping
carts. They rely on the visitor having them enabled. You may want to
consider using session variables instead, or even writing the shopping
cart information to a database.

/P.

Feb 25 '06 #2
>But you are right - cookies are not the ideal way to manage shopping
carts. They rely on the visitor having them enabled. You may want to
consider using session variables instead, or even writing the shopping
cart information to a database.

i am not that familar with SQL so can i have a little help with the
syntax for writing it to a database because that would be ideal.

Feb 25 '06 #3
>dblSubTotal = 0
for i = 1 to iItemCount
dblSubTotal = dblSubTotal +
Request.Cookies ("ShoppingCart" )("ISBNPrice"&i Count)
next

im having trouble setting up this loop as well where would i put it in
my code

Feb 25 '06 #4

isaac2004 wrote:
dblSubTotal = 0

for i = 1 to iItemCount
dblSubTotal = dblSubTotal +
Request.Cookies ("ShoppingCart" )("ISBNPrice"&i Count)
next

im having trouble setting up this loop as well where would i put it in
my code


Where did you try to put it and what was the error?

/P.

Feb 25 '06 #5

isaac2004 wrote:
But you are right - cookies are not the ideal way to manage shopping

carts. They rely on the visitor having them enabled. You may want to
consider using session variables instead, or even writing the shopping
cart information to a database.

i am not that familar with SQL so can i have a little help with the
syntax for writing it to a database because that would be ideal


The best way to do it is to use a saved parameter query. Bob has
posted huge amounts about them. Here are some links:

http://groups.google.com/group/micro...UTF-8&oe=UTF-8
http://groups-beta.google.com/group/...d322b882a604bd
http://groups.google.com/group/micro...e36562fee7804e

/P.

Feb 25 '06 #6
>Where did you try to put it and what was the error?

there was no error it just didnt read the iItemCount, i put it right
before the prompt for the dblsubtotal.

Feb 25 '06 #7

isaac2004 wrote:
Where did you try to put it and what was the error?


there was no error it just didnt read the iItemCount, i put it right
before the prompt for the dblsubtotal.


Did you check the cookie to see if there was a value for iItemCount?
Are you adding the price to the cookie?

Also, your html is in such a mess that it's always possible the thing
you expect to see isn't displaying correctly. I've copied your code
into Dreamweaver, and chunks of it are hidden from view because of
overlapping and unclosed tags.

/P.

Feb 25 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3258
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old scripts working on a new server with the most recent version of PHP. I've pretty much taken care of all the various errors that were popping up. ...
2
2847
by: Don Grover | last post by:
I am retrieving costs and product id's from a sql db. and need to build a shopping cart around it. How do I store the selected items and qty req so I can move into another catalog and total up as im going. Just a couple of hints will do, Im familiar with vb script but not java based code , and im wondering how to store what they select so I...
1
3567
by: madison | last post by:
Hi, I am trying to start a website using paypals shopping cart function. If i have 10 items and they sell out, how do I make it so the item is then listed as sold out. The next person would not be able to come along and add it to their shopping cart. thanks joy
1
1798
by: Jia Sun | last post by:
hello , everybody , i need a similar program , just like fancyimport.com if possible, pls contact me ,thank you very much . inchina@gmail.com
17
2330
by: Phil McKraken | last post by:
I am having a problem putting together a shopping cart with the below script. Everything displays fine, adds totals fine, and works perfect EXCEPT if you choose the 9.95 item #5 BY ITSELF the total displayed is $9.94 ! If you add ANYTHING else the total is correct, 9.95 plus whatever you add. That is the only price in these samples that is...
2
2313
by: isaac2004 | last post by:
hi i am creating a basic asp site that uses cookies to manage a cart for an online store. whenever i open this page without adding anything to the cart. i get an error message. here is my code <%@ Language=VBScript %> <% Option Explicit %> <!--#include file="DatabaseConnect.asp"--> <!--#include...
3
1537
by: isaac2004 | last post by:
hello i am making a spoof online book store site for a class and I was wondering how i could fix a problem i am having. I have two tables, one the cart and the other a table with book descriptions. what i am trying to do is display the book info for the cart through a SQL statement. the only problem is when i do this it just outputs the info...
0
3687
by: samjam | last post by:
Below is some coding in a program i am using, i would like to know how i can get the text bigger or bolder on my webpage, This is the section of text i would like bigger or bolder (This is a very rare lacquered tea caddy c1840. The outside of the caddy has wonderful scenes on each side which are really finely painted. The caddy stands on claw...
3
2884
by: Paulo | last post by:
Hi, beginner on asp.net 2.0 C# VS 2005, how can I use the shopping cart concept on my application? When the user clicks add item, it will be stored on some storage format, I dont know what is the term: temp/global DataSet, etc... and it should be read on other web-form to checkout the items... Can you point me to the right direction? ...
0
7521
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7802
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7889
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6145
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5155
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2020
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1134
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
841
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.