session做的购物车程序

购物车程序

作者:周培公
这个程序是用session做的,如果改成cookie可能持久性上会更好。

<%

'产品ID  Session("products")
'产品数量 Session("productCounts")
'购物车程序
function addCart(productID)
  '把商品添加到购物车
  dim products,productCounts
    products=session("products")
  productCounts=Session("productCounts")
 
  dim tempProducts,tempProductCounts
    tempProducts = Split(ProductID,",")
 
  dim i
    For i=0 To UBound(tempProducts)
      tempProducts(i) =trim(tempProducts(i))
       If Len(products) = 0 Then
         products = tempProducts(i)
      productCounts="1"
         ElseIf InStr( products, tempProducts(i) ) <= 0 Then
          products = products&","&tempProducts(i)
      productCounts=productCounts&","&"1"
       End If
    Next
 session("products")=products
 Session("productCounts")=productCounts
end function
function updateCart(productID,Counts)
 '修改购物车中的商品数量
  dim products,productCounts
  products=""
  productCounts=""
  dim tempProducts,tempProductCounts
    tempProducts = Split(ProductID,",")
  tempProductCounts = Split(Counts,",")
 
  dim i
    For i=0 To UBound(tempProducts)
  if len(products)>0 then
   tempProducts(i) =trim(tempProducts(i))
   products = products&","&tempProducts(i)
  
   tempProductCounts(i) =trim(tempProductCounts(i))
   if tempProductCounts(i)<>"" then
    productCounts=productCounts&","&tempProductCounts(i)
   else
    productCounts=productCounts&",0"
   end if
  else
   tempProducts(i) =trim(tempProducts(i))
   products = tempProducts(i)
  
   tempProductCounts(i) =trim(tempProductCounts(i))
   if tempProductCounts(i)<>"" then
    productCounts=tempProductCounts(i)
   else
    productCounts="0"
   end if
  end if
    Next
  session("products")=products
  Session("productCounts")=productCounts
end function
function delCart(productID)
 '从购物车中删掉指定的商品
  dim products,tempProducts
    products=session("products")
    tempProducts = Split(ProductID,",")
 
  dim i
  i=0
  For i=0 To UBound(tempProducts)
    if Len(products)>1 then
         If InStr(products,tempProducts(i))>0 Then
       products = Replace(products,tempProducts(i),"0")
      End If
    elseif Len(products)=1 then
         products = Replace(products,tempProducts(i),"0")
      end if 
  Next
  session("products")=products
end function
function clearCart()
 '清空购物车
  session("products")=""
  Session("productCounts")=""
end function
function displayCart(products,productCounts)
 '显示,统计购物车中的商品。
 '此外略去
end function
 

 %>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值