博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
制作购物车程序(转)
阅读量:2499 次
发布时间:2019-05-11

本文共 4930 字,大约阅读时间需要 16 分钟。

*****
' To find the actual runtime code scroll WAY DOWN....

' This function is written to enable the adding of multiples of an

item
' but this sample always just adds one. If you wish to add different
' quantities simply replace the value of the Querystring parameter
count.
' We didn't do this because we wanted to keep the whole thing simple
and
' not get into using forms so it stayed relatively readable.
Sub AddItemToCart(iItemID, iItemCount)
If dictCart.Exists(iItemID) Then
dictCart(iItemID) = dictCart(iItemID) + iItemCount
Else
dictCart.Add iItemID, iItemCount
End If
Response.Write iItemCount & " of item # " & iItemID & "
have been added to your cart.
" & vbCrLf
End Sub

Sub RemoveItemFromCart(iItemID, iItemCount)

If dictCart.Exists(iItemID) Then
If dictCart(iItemID) <= iItemCount Then
dictCart.Remove iItemID
Else
dictCart(iItemID) = dictCart(iItemID) -
iItemCount
End If
Response.Write iItemCount & " of item # " &
iItemID & " have been removed from your cart.
" & vbCrLf
Else
Response.Write "Couldn't find any of that item
your cart.
" & vbCrLf
End If
End Sub

Sub ShowItemsInCart()

Dim Key
Dim aParameters ' as Variant (Array)
Dim sTotal, sShipping

%>

Item # Description Quantity Remove Item From Cart Price Totals
> >  HREF="./shopping.asp?action=del&item=&count=(Key) %>">Remove All $> $(dictCart(Key) * CSng(aParameters(2)),2) %>

'Calculate shipping - you might want to pull this out into

a function if your shipping
' calculations are more complicated then ours. ;)
If sTotal <> 0 Then
sShipping = 7.5
Else
sShipping = 0
End If
sTotal = sTotal + sShipping
%>

S+H:ALIGN="Right">$
Total:ALIGN="Right">$
End Sub

Sub ShowFullCatalog()

Dim aParameters ' as Variant (Array)
Dim I
Dim iItemCount ' Number of items we sell
' If you are really going to use this sample this should
probably be pulled from a DB
iItemCount = 3
%>

Image Description Price Add Item To Cart
<%=%20aParameters(0)%20%> $
End Sub

Sub PlaceOrder()

Dim Key
Dim aParameters ' as Variant (Array)
Dim sTotal, sShipping

%>

Item # Description Quantity Price Totals
> > $> $(dictCart(Key) * CSng(aParameters(2)),2) %>

'Calculate shipping - you might want to pull this out into

a function if your shipping
' calculations are more complicated then ours. ;)
If sTotal <> 0 Then
sShipping = 7.5
Else
sShipping = 0
End If
sTotal = sTotal + sShipping
%>

S+H:ALIGN="Right">$
Total:ALIGN="Right">$
End Sub

' We implemented this this way so if you attach it to a database

you'd only need one call per item
Function GetItemParameters(iItemID)
Dim aParameters ' Will contain 3 string values : image path,
description, price
' However we need to keep price
so it can be converted to a
' single for computation hence
no currency symbol. This array
' can also be expanded to
contain any other information about the
' product that you might want to
pull from the DB.
Select Case iItemID
Case 1
aParameters = Array
("./images/shop_shirt.gif", "ASP 101 T-Shirt", "15.00")
Case 2
aParameters = Array
("./images/shop_kite.gif", "ASP 101 Kite", "17.50")
Case 3
aParameters = Array
("./images/shop_watch.gif", "ASP 101 Watch", "35.00")
Case 4 ' Not in use because we couldn't draw a pen
in a few seconds!
aParameters = Array
("./images/shop_pen.gif", "ASP 101 Pen", "5.00")
End Select
' Return array containing product info.
GetItemParameters = aParameters
End Function
%>

' Declare our Vars
Dim dictCart ' as dictionary
Dim sAction ' as string
Dim iItemID ' as integer
Dim iItemCount ' as integer

' Get a reference to the cart if it exists otherwise create it

If IsObject(Session("cart")) Then
Set dictCart = Session("cart")
Else
' We use a dictionary so we can name our keys to correspond
to our
' item numbers and then use their value to hold the
quantity. An
' array would also work, but would be a little more complex
and
' probably not as easy for readers to follow.
Set dictCart = Server.CreateObject("Scripting.Dictionary")
End If

' Get all the parameters passed to the script

sAction = CStr(Request.QueryString("action"))
iItemID = CInt(Request.QueryString("item"))
iItemCount = CInt(Request.QueryString("count"))
%>

' Select action based on user input
Select Case sAction
Case "add"
AddItemToCart iItemID, iItemCount
ShowItemsInCart
%>
Case "del"
RemoveItemFromCart iItemID, iItemCount
ShowItemsInCart
%>
Case "viewcart"
ShowItemsInCart
%>
Case "checkout"
PlaceOrder
%>

Thank you for your order!

If this had been an actual shopping cart, this is
where you would have had them enter
their personal information and payment method and
then taken care of any backend
processing before finalizing their order. However
as this is a shopping cart sample
and this is where security becomes a problem,
we'll leave it for a future sample.
Case Else ' Shop
ShowFullCatalog
%>
End Select

' Return cart to Session for storage

Set Session("cart") = dictCart
%>

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-124749/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10294527/viewspace-124749/

你可能感兴趣的文章
How it works(3) Tilestrata源码阅读(A)
查看>>
How it works(12) Tileserver-GL源码阅读(A) 服务的初始化
查看>>
uni-app 全局变量的几种实现方式
查看>>
echarts 为例讲解 uni-app 如何引用 npm 第三方库
查看>>
uni-app跨页面、跨组件通讯
查看>>
springmvc-helloworld(idea)
查看>>
JDK下载(百度网盘)
查看>>
idea用得溜,代码才能码得快
查看>>
一篇掌握python魔法方法详解
查看>>
数据结构和算法5-非线性-树
查看>>
数据结构和算法6-非线性-图
查看>>
数据结构和算法7-搜索
查看>>
数据结构和算法8-排序
查看>>
windows缺少dll解决办法
查看>>
JPA多条件动态查询
查看>>
JPA自定义sql
查看>>
BigDecimal正确使用了吗?
查看>>
joplin笔记
查看>>
JNDI+springmvc使用
查看>>
vue+springboot分页交互
查看>>