473,717 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Once the info is stored in the Session variables, they're redirected to the
ViewCart.asp page:
''response.writ e Request.Form & "<br><br>"

if Request.Form("a ction") = "add" then

count = 0
for each item in Request.form("i ntProdID")
'Main Program
intProdID = split(Request.F orm("intProdID" ), ",")
strProdName = split(Request.F orm("strProdNam e"), ",")
intQuant = split(Request.F orm("intQuant") , ",")
intProdPrice = split(Request.F orm("intProdPri ce"), ",")
productType = split(Request.F orm("productTyp e"), ",")
clearcart = Request.Form("c lear")

if clearcart = "true" then
Session("ItemCo unt") = 0
clearcart = ""
end if

''response.writ e intQuant(count) & "<br>"
if trim(Cint(intQu ant(count))) > 0 then

intItemCount = Session("ItemCo unt")

if intItemCount = 0 then
intItemCount = 1
Session("ItemCo unt") = intItemCount
intItemCount = intItemCount + 1
Session("ItemCo unt") = intItemCount
end if

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

Session("ItemCo unt") = intItemCount
Session(strProd ) = trim(intProdID( count))
Session(strQnty ) = trim(Cint(intQu ant(count)))
Session(strDesc ) = trim(strProdNam e(count))
Session(strCost ) = trim(intProdPri ce(count))
Session(strType ) = trim(productTyp e(count))

''response.writ e count & ": Prod:" & intProdID(count ) & " Name:" &
strProdname(cou nt) & " Qnty:" & intQuant(count) & " Cost:" &
intProdPrice(co unt) & " Type:" & productType(cou nt) & "<br>"

end if ''intQuant(coun t) <> 0

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

''response.writ e "<br>Cart:< br>"
''for intItemCount = 1 to Session("ItemCo unt")
'' response.write intItemCount & ": Prod:" & Session("Prod_" &
Cstr(intItemCou nt)) & " Name:" & Session("Desc_" & Cstr(intItemCou nt)) & "
Qnty:" & Session("Qnty_" & Cstr(intItemCou nt)) & " Cost:" & Session("Cost_"
& Cstr(intItemCou nt)) & " Type:" & Session("Type_" & Cstr(intItemCou nt)) &

<!--Start Basket Contents-->

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(s trQnty)) *
Cint(Session(st rCost)))
intInventory = Cint(999)
if intInventory < Cint(Session(st rQnty)) then status = "<font
if intInventory >= Cint(Session(st rQnty)) 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="checkou t.asp" method="post" id="form1" name="form1">
<td width="10%" align="left"><f ont face="Arial" size="1">&nbsp; <%=
Session(strProd ) %></font></td>
<td width="50%" align="left"><f ont face="Arial" size="1">&nbsp; <%=
Session(strDesc ) %></font></td>
<td width="10%" align="right">< font face="Arial" size="1"> $<%=
formatNumber(Se ssion(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((S ession(strQnty) * Session(strCost )), 2) %></font></td>
<td width="15%" align="center"> <font face="Arial" size="1"> <%= status
<td><input name="intItemID " type="hidden" value="<%= count %>">
<input name="intProdID " type="hidden" value="<%=
Session(strProd ) %>">
<input name="strProdNa me" type="hidden" value="<%=
Session(strDesc ) %>">
<input name="intProdPr ice" type="hidden" value="<%=
Session(strCost ) %>">
<input name="intQuant" type="hidden" value="<%=
Session(strQnty ) %>">
<input type="submit" name="control" value="Delete"> </td>
response.write "<b>Cart is empty</b>"
end if


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

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

Similar topics

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 behaviour to maintain security and prevent session stealing. I've no idea to maintain session in shopping cart with SSL in check out form because if I do it with cookies the same security problem exist there, anyone can steal cookie in non SSL...
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 track user session from non SSL to SSL checkout page as the SessionID changes when shifting to SSL (to prevent session stealing/ hijacking). I'm tracking user session by putting SessionID in cart DB with products. Given below the preview of cart...
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 they are not logged in they will be prompted to either login or register before they can proceed to the checkout. There is NO requirement to allow users to add items to a shopping cart, and return at some time in the future and still have...
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 which is loosely based on the e-commerce example in the quickstarts tutorial. In the cart display I have provided functionality so that when a user clicks on a product name a popup is opened with the full product details displayed.
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 in table. All products and cart status pages are on non SSL connection. On checkout to get secure user information I shifted connection to SSL but when shifting to SSL, the SessionID changed (As is this is default behavior of IIS to prevent...
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 timeout, but I was finding that people could take longer than 20 minutes between pages. So my question is, what are peoples recommendations here, should I continue using the session variables or should I adopt a cookie approach and store...
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 fnGetShoppingCartText() { if (Session != null) { ArrayList cart = (ArrayList)Session;
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 on my system. I would like to be able to access the session of the user that submitted the order, and clear their basket. I don't really want to store their session in the database just to facilitate this.
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 display values placed in session. foreach($_SESSION as $key=>$value){ echo $value; echo $value;
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
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
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.