HOME > ASP > ASP Forum > เรียนท่านเทพทั้งหลายช่วยแนะนำระบบตะกร้าทีคับ แบบว่าพึ่งหัดเขียนโปรแกรมนะครับ อยากจะศึกษาเรื่องการทำระบบตะกร้าด้วย session cookie
<%
If Session("customer_id") = "" Then Response.Redirect "login.asp"
%>
<%
CONST CARTPID=0
CONST CARTPNAME=1
CONST CARTPPRICE=2
CONST CARTPQUANTITY=3
Dim foundIt, i, product_id, product_name, product_price, newQ, deleteProduct
If Not IsArray(Session("cart")) Then
Dim localCart(4,20)
Else
localCart = Session("cart")
End If
If product_id <> "" Then
foundIt = False
For i = 0 To Ubound(localCart,2)
If localCart(CARTPID, i) = product_id Then
localCart(CARTPQUANTITY, i) = localCart(CARTPQUANTITY, i) + 1
foundIt = True
Exit For
End If
Next
If Not foundIt Then
For i = 0 To Ubound(localCart, 2)
If localCart(CARTPID,i) = "" Then
localCart(CARTPID,i) = product_id
localCart(CARTPNAME,i) = product_name
localCart(CARTPPRICE,i) = product_price
localCart(CARTPQUANTITY,i) = 1
Exit For
End If
Next
End If
End If
If Request.Form("updateQ") <> "" Then
For i = 0 To Ubound(localCart,2)
newQ = Trim(Request.Form("pq" & localCart(CARTPID,i)))
deleteProduct = Trim(Request.Form("pd" & localCart(CARTPID,i)))
If newQ = "" Or newQ = "0" Or deleteProduct <> "" Then
localCart(CARTPID,i) = ""
Else
If IsNumeric(newQ) Then
localCart(CARTPQUANTITY,i) = newQ
End If
End If
Next
End If