明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

購物車范例(購物車頁面 )

[摘要]<!--checkbag.asp--><!--shoppingcart page--><% response.expires = 0 response.expiresabsolute = Now() - 1 response.addHeader ...
<!--checkbag.asp-->

<!--shoppingcart page-->

<%  
    response.expires = 0
    response.expiresabsolute = Now() - 1
    response.addHeader "pragma","no-cache"
    response.addHeader "cache-control","private"
    Response.CacheControl = "no-cache"
%>

<!--#include file= "conn.asp"-->
<!--#include file= "char.inc"-->

<%
    'id_type=request("id_type")
    obj=request("obj")       '用做檢測是否是正常購買后的進(jìn)入購物車取obj參數(shù)
    rid=session("id")         '取出會(huì)員id
    dim x,i
    dim obj_bag,bag_item,cart
           'obj_bag          ----購物車
           'bag_item        ----商品的信息數(shù)據(jù)集合
           'cart                ----一件商品的信息數(shù)據(jù)集合
    dim p_id,p_name,p_price,p_manu,p_type,p_size,p_color,p_num,p_total,sum
            'p_id               ----商品id號(hào)
            'p_name         ----商品名稱
            'p_price          ----價(jià)格
            'p_manu         ----制造商
        'p_type           ----商品式樣
            'p_size           ----尺寸
        'p_color          ----顏色
            'p_num           ----數(shù)量
            'p_total           ----小計(jì)
            'sum              ----合計(jì)金額

    dim id1

    if obj="1" then                                     obj為1說明由菜單欄點(diǎn)擊進(jìn)入的
        if not isobject(Session("Bag")) then            如果Session("Bag")不是對象,說明購物車為空
            response.write "<script language=""javascript"">"
            response.write"alert(""購物車為空!"");" & chr(13)
            response.write "window.location='index.asp'"
            response.write "</script>"
            response.end
        else
            set obj_bag=Session("Bag")           若購物車不為空,將它賦給對象obj_bag
        end if
    else
        if isobject(Session("Bag")) then                  若不是菜單欄點(diǎn)擊進(jìn)入的,則將購物車信息賦給對象obj_bag

            set obj_bag=Session("Bag")
        else                                                         若購物車為空,說明購物車內(nèi)沒有商品,則返回首頁
            response.write "<script language=""javascript"">"
            response.write"alert(""T購物車為空!"");" & chr(13)
            response.write "window.location='index.asp'"
            response.write "</script>"
            response.end
        end if
      end if
            'response.write "<script>alert("""& isobject(obj_bag) &""")</script>"
      
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'判斷單擊的是購物車頁面下方的哪一個(gè)按鈕
''''''''''''''''''''''''''''''''''''''''

    select case request("action")          取得按鈕信息
   如果選擇刷新則重新計(jì)算商品的價(jià)值及總價(jià)
   將當(dāng)前信息計(jì)算寫入購物車并顯示購物車
        case "refresh"        若為刷新   
            for each cart in obj_bag.items
                p_name=cart(0)     將購物車中的信息數(shù)據(jù)集合分別賦值給變量
                p_manu=cart(1)
                p_type=cart(2)
                p_size=cart(3)
                p_color=cart(4)
                p_price=cart(5)
                p_num=cart(6)
                p_id=cart(7)

                if request("checkBox_" & p_id)<>"" then         取得取消單選框的值,如果不為空,即打鉤
                    if obj_bag.Exists(p_name) then         如果商品已存在刪除該商品
                        obj_bag.remove(p_name)
                    end if
                else
                    p_num=trim(request("quantity"&p_name))     若沒有該操作,寫入購物車
                    if ((not IsNumeric(p_num)) or (p_num<="0") or (instr(1,p_num,".")<>0)) then
                        p_num=1
                    end if
                    bag_item=array(p_name,p_manu,p_type,p_size,p_color,p_price,p_num,p_id)
                    'response.write "p_num=" & p_num & "<br>"
                end if
            next
            set Session("Bag")=obj_bag            將obj_bag對象里的信息,寫入Session("Bag")

如果選擇去收銀臺(tái)則準(zhǔn)備開始接收付款
將當(dāng)前信息寫入購物車并轉(zhuǎn)向收銀程序
        case "check"                                               按鈕為購買的時(shí)候
            for each cart in obj_bag.items            循環(huán)cart將其所有信息都賦給變量
                p_name=cart(0)
                p_manu=cart(1)
                p_type=cart(2)
                p_size=cart(3)
                p_color=cart(4)
                p_price=cart(5)
                p_num=cart(6)
                p_id=cart(7)
            
                if request("checkBox_" & p_id)="" then  如果取消單選框?yàn)榭,取id1的值
                    id1=p_id & "," & id1                 將他們有逗號(hào)形式連接
                end if
            next
            id1=left(id1,len(id1)-1)                                  
            shopping_id=request("id")
            set obj_bag=session("bag")
            set session("obj_bag")=obj_bag    
            call insertDB(id1)                                             調(diào)用函數(shù)
    end select
%>
'輸出HTML
。。。。。。。。。(略)