INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Optimization

Simple shoping cart by shaddow
Posted: 5 Mar 04 (Edited 6 Mar 04)

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.

Back to Microsoft: ASP (Active Server Pages) FAQ Index
Back to Microsoft: ASP (Active Server Pages) Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close