473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Session based Shopping Cart

I'd been using an Access database based shopping cart, but wanted to change
it so that it would use session variables. I have a form that's submitted
to a page called addtocart.asp that contains the following information:

intProdID -- ProductID
strProdName -- Product Name
intQuant -- Quantity
intProdPrice -- Price
productType -- Type of product (ie. Wine, Cheese, etc...)

I also made the cart be able to process more than one item at a time. For
example, I had an event where customers could specify how many Wine or
Cheese tickets they'd like to purchase. They select the amounts and hit
submit, which takes them to the addtocart.asp page. I left a bunch of
trouble shooting items REM'd out. They were useful when I was designing the
cart and since it took me a while to get to work perfectly, I wanted to
share it with the public. If you want more details, email me directly --
just be aware, I typically only check this hotmail account once or twice a
month.

Once the info is stored in the Session variables, they're redirected to the
ViewCart.asp page:
<%@ LANGUAGE="VBSCRIPT" %>
<%
''addtocart.asp
''response.write Request.Form & "<br><br>"

if Request.Form("action") = "add" then

count = 0
for each item in Request.form("intProdID")
'Main Program
intProdID = split(Request.Form("intProdID"), ",")
strProdName = split(Request.Form("strProdName"), ",")
intQuant = split(Request.Form("intQuant"), ",")
intProdPrice = split(Request.Form("intProdPrice"), ",")
productType = split(Request.Form("productType"), ",")
clearcart = Request.Form("clear")

if clearcart = "true" then
Session("ItemCount") = 0
clearcart = ""
end if

''response.write intQuant(count) & "<br>"
if trim(Cint(intQuant(count))) > 0 then

intItemCount = Session("ItemCount")

if intItemCount = 0 then
intItemCount = 1
Session("ItemCount") = intItemCount
else
intItemCount = intItemCount + 1
Session("ItemCount") = intItemCount
end if

strProd = "Prod_" & Cstr(intItemCount)
strQnty = "Qnty_" & Cstr(intItemCount)
strDesc = "Desc_" & Cstr(intItemCount)
strCost = "Cost_" & Cstr(intItemCount)
strType = "Type_" & Cstr(intItemCount)

Session("ItemCount") = intItemCount
Session(strProd) = trim(intProdID(count))
Session(strQnty) = trim(Cint(intQuant(count)))
Session(strDesc) = trim(strProdName(count))
Session(strCost) = trim(intProdPrice(count))
Session(strType) = trim(productType(count))

''response.write count & ": Prod:" & intProdID(count) & " Name:" &
strProdname(count) & " Qnty:" & intQuant(count) & " Cost:" &
intProdPrice(count) & " Type:" & productType(count) & "<br>"

end if ''intQuant(count) <> 0

''response.write intItemCount & ": Prod:" & Session(strProd) & " Name:" &
Session(strDesc) & " Qnty:" & Session(strQnty) & " Cost:" & Session(strCost)
& " Type:" & Session(strType) & "<br>"
count = count + 1
next

''response.write "<br>Cart:<br>"
''for intItemCount = 1 to Session("ItemCount")
'' response.write intItemCount & ": Prod:" & Session("Prod_" &
Cstr(intItemCount)) & " Name:" & Session("Desc_" & Cstr(intItemCount)) & "
Qnty:" & Session("Qnty_" & Cstr(intItemCount)) & " Cost:" & Session("Cost_"
& Cstr(intItemCount)) & " Type:" & Session("Type_" & Cstr(intItemCount)) &
"<br>"
''next
''response.end
%>

<%@ LANGUAGE="VBSCRIPT" %>
<!--Start Basket Contents-->

<%
''ViewCart.asp
if intItemCount <> 0 then
intShipping = 0
intService = 0
intSubTotal = 0
intTotal = 0
strShipMethod = "No Tax"

for count = 1 to intItemCount
strProd = "Prod_" & Cstr(count)
strQnty = "Qnty_" & Cstr(count)
strDesc = "Desc_" & Cstr(count)
strCost = "Cost_" & Cstr(count)
strType = "Type_" & Cstr(count)
intSubTotal = intSubTotal + (Cint(Session(strQnty)) *
Cint(Session(strCost)))
intInventory = Cint(999)
if intInventory < Cint(Session(strQnty)) then status = "<font
color=red>On-Order</font>"
if intInventory >= Cint(Session(strQnty)) then status = "In-Stock"
strShipMethod = "NJ"
if strShipMethod = "NJ" then intTaxRate = .06 else intTaxRate = .00
intTax = round (((intSubTotal) * intTaxRate), 2)
intTotal = round ((intSubTotal + intShipping + intService + intTax), 2)
%>
<tr><form action="checkout.asp" method="post" id="form1" name="form1">
<td width="10%" align="left"><font face="Arial" size="1">&nbsp;<%=
Session(strProd) %></font></td>
<td width="50%" align="left"><font face="Arial" size="1">&nbsp;<%=
Session(strDesc) %></font></td>
<td width="10%" align="right"><font face="Arial" size="1"> $<%=
formatNumber(Session(strCost), 2) %> &nbsp</font></td>
<td width="10%" align="center"><font face="Arial" size="1">&nbsp;<%=
Session(strQnty) %></font></td>
<td width="10%" align="right"><font face="Arial" size="1"> $<%=
formatNumber((Session(strQnty) * Session(strCost)), 2) %></font></td>
<td width="15%" align="center"><font face="Arial" size="1"> <%= status
%></font></td>
<td><input name="intItemID" type="hidden" value="<%= count %>">
<input name="intProdID" type="hidden" value="<%=
Session(strProd) %>">
<input name="strProdName" type="hidden" value="<%=
Session(strDesc) %>">
<input name="intProdPrice" type="hidden" value="<%=
Session(strCost) %>">
<input name="intQuant" type="hidden" value="<%=
Session(strQnty) %>">
<input type="submit" name="control" value="Delete"></td>
</form>
</tr>
<%
next
else
response.write "<b>Cart is empty</b>"
end if

%>

<!--End Basket Contents-->
May 26 '06 #1
0 2453

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

Similar topics

1
by: Adil Akram | last post by:
I've developed a shopping cart application in ASP. To maintain the shopping cart session, I've used the session ID, but while it shifts to SSL pages, the session ID changed which is its default...
4
by: Adil Akram | last post by:
I've developed a shopping cart app in ASP, to secure transaction by SSL, it 've put only the checkout page in SSL but all other pages i.e. product, cart etc remains on non SSL connection. How can I...
2
by: Paul Hobbs | last post by:
Hi All, I am developing a site that makes use of a standard shopping cart. Anyone can add items to the cart, but only registered users can actually check out. When a user tries to check out, if...
2
by: Joe Molloy | last post by:
Hi, This isn't a mission critical question but I thought I'dl throw it out there for your feedback as it's a bit curious. I have developed a shopping cart for an application I'm working on...
1
by: Adil Akram | last post by:
I have created a site shopping cart in ASP.net. I am using ASP session object's SessionID on non SSL connection to track session. While adding products to cart DB I insert product and SessionID...
7
by: Joseph Byrns | last post by:
I have written a shopping cart type web application using session variables to store the shopping cart details (with a timeout of 59 minutes). Originally my timeout was set to the default 20 minute...
6
by: KevinGravelle | last post by:
What is wrong with this picture? I'm trying to set my shopping cart text on my home page using the following function that is executed when the class is constructed: protected string...
4
by: Nick Gilbert | last post by:
Hi, Is it possible to access the Session of an arbitary user from an aspx page? On an e-commerce site, I am notified of payment success via a callback from the payment server to an ASPX page...
5
by: rahia307 | last post by:
i developed session based shopping cart. using this code. $_SESSION= array( 'prd_name' => $prd_name, 'unit_price' => $unit_price, 'qty' => $qty, 'id_prd' => $id_prd); and i use this code to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.