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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple shoping cart

Optimization

Simple shoping cart

by  shaddow  Posted    (Edited  )
I've made an simple shoping cart using Session object and Dictionary Object as well (let the objects work for us)

This example should work, i had time to make an working example.

You can see another working example thanks to Onpnt here
http://www.onpntwebdesigns.com/cartTest.asp


Code:
cart.asp
<%
if not isObject(Session("cart")) then 
	set Session("cart")=Server.CreateObject("Scripting.Dictionary")
end if

add=Request("add")
qty=Request("qty")
del=Request("del")

if add<>"" then
 'check if data is no there
 if not Session("cart").Exists(add) then  'add to cart
 'get data from database this example is without
   set recData=Server.CreateObject("Scripting.Dictionary")
   recData.Add "cart_no",add
   recData.Add "qty",1
   recData.Add "price",100
 'store the cart to it's cart_no
  Session("cart").Add add,recData
 else 'flight_id exists
  'add only the qty
  Session("cart")(add)("qty")=Session("cart")(add)("qty")+CInt(qty)
 end if
end if
if del<>"" then
 'remove from cart
 Session("cart").Remove(del)
end if
'store back to session object

 
'here display your cart
 if IsObject(Session("cart")) then
	if Session("cart").Count>0 then
		cartItems=Session("cart").Items
		For i=Lbound(cartItems) to Ubound(cartItems)
			cart_no=cartItems(i)("cart_no")
			price=cartItems(i)("price")
			qty=cartItems(i)("qty")

			Response.Write (i+1)&": "&cart_no&" - "&price&" - "& qty &"<br>"
		Next
	else
		Response.Write ("ur cart is empty")
	end if
end if
%>



How to use

cart.asp?add=101 - will add this rec id into cart
cart.asp?add=101&qty=2 - will add 2 to qty of the 101
cart.asp?del=101 - will remove this cart

I hope this code will help.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top