艺文类聚txt:购物车程序的规划

来源:百度文库 编辑:九乡新闻网 时间:2024/05/04 18:42:53

一、购物车程序的规划功能模块有:添加物品、删除物品、清空购物车、修改购买物品数量在物品展示页面以物品的ID号为参数来运行JS函数PutWare(strID)PutWare(strID)函数内容如下:此函数功能,打开购物车shopping.asp并传传递当前页变量参数(acction,id,ptcount)
物品展示外的调用如下:添加物品:')">放入购物车
二、添加商品代码分析:<%
'添加商品
if request("action")="add" then
call AddProduct(request("spid"),CInt(request("PtCount")))
end if
%>此段判断是否要放物品在购物车中,如果是的话,调用AddProduct(strPcID,intCount)过程,过程代码如下:<%
sub AddProduct(strPcID,intCount)ProductList = Session("ProductList")  '商品ID列表
ProductCount=Session("ProductCount")  '商品数量列表
Products = Split(ProductList, ",")  '分割物品种类为数组
PtCounts = Split(ProductCount, ",")  '分割物品数量为数组
'下面为寻求购物车中是否有该商品,如果没有则追加
For i=0 To UBound(Products)'返回Products的元素个数,及数组Products的最大的下标。
    if Products(i)=strPcID then exit for
Next
'还没有该商品,追加
if i>UBound(Products) then
  Session("ProductList") = ProductList & strPcID & ","
  Session("ProductCount") = ProductCount & intCount & ","
else
  '如果商品已在车中,累加数量
  PtCounts(i)=Cint(PtCounts(i)) + intCount
  Session("ProductList") =join(Products,",")
  Session("ProductCount") =join(PtCounts,",")'将数组转换成字串
end if
end sub%>三、删除商品代码分析:删除物品:')">
<%
if request("action")="modi
y" then
call ModifyProduct(request("spid"),CInt(request("PtCount")))
end if
%>此段判断是否要删除购物车中的指定物品,如果是的话,调用ModifyProduct(strPcID,intCount)过程,过程代码如下:<%
sub ModifyProduct(strPcID,intCount)
ProductList = Session("ProductList")  '商品ID列表
ProductCount=Session("ProductCount")  '商品数量列表
Products = Split(ProductList, ",")
PtCounts = Split(ProductCount, ",")
'寻求购物车中是否有该商品,如果有则删除
For i=0 To UBound(Products)
if Products(i)=strPcID then exit for
Next
'还有该商品,删除该商品指定的数量
if i<=UBound(Products) then
PtCounts(i)=intCount 
if PtCounts(i) < 0 then  PtCounts(i)=0 '防止溢出
end if
'将数组转换成字串
Session("ProductList") =join(Products,",")
Session("ProductCount") =join(PtCounts,",")
end sub
%>三、清空购物车代码分析:清空购物车:<%
if request("action")="clear" then
call clearProduct()
end if
%>此段判断是否要清空购物车中的物品,如果是的话,调用clearProduct()过程,过程代码如下:<%
sub clearProduct()
Session("ProductList")=""
Session("ProductCount")=""
end sub
%>
四、其他细节方面主要的asp购物车功能基本已经完成,现在说下细节方面的程序规划与实现1、在修改购物车中物品的数量。直接用JS里的onclick驱动SetCount函数就可以了,实现方法如下:',document.WareList.ptCount<%=rs("id")%>.value)"> SetCount函数如下:function SetCount(strID,strCount){
if (CheckValue(strCount)){
window.location="shopping.asp?action=modify" + "&spid=" + strID + "&PtCount=" + strCount;
  }
}2、选定商品之后提交提交时就没有什么技术了,直接把购物车中的表单值放在数据库中就行了,之后读取、修改什么的,或者跳转到一个用户信息表单,填好用户信息再提交,自己举一反三吧!为做到程序的优化,常用到的函数或者过程可以放到指定的asp文件里,比如这里的AddProduct(strPcID,intCount),ModifyProduct(strPcID,intCount)、clearProduct()等。
本文来自:流浪人E部落 http://bbs.liulang01.cn版权所有(无注明,视为侵权)