Shopping Cart Example (Processing page)

Source: Internet
Author: User
Tags array chr trim
<!--put2bag.asp-->

<%@ Language=vbscript%>
<%
' Id_type=request ("Id_type")

On Error Resume Next
Response.Buffer = True
Response.Expires = 0
Dim Obj_bag,bag_item,cart
' Obj_bag----Shopping cart
' Bag_item----Product Information data collection
' Cart----Information data collection for a product
Dim p_id,p_name,p_price,p_manu,p_type,p_size,p_color,p_num,p_temp
' P_ID----Product ID number
' P_name----Product Name
' P_price----Original price
' P_manu----commodity manufacturer
' P_type----Product style
' P_size----Product size
' P_color----Product color
' p_num----Number of commodities
' P_temp----temporary storage p_num


If session ("login") = "" Then
Response.Write "<script langue=" "JavaScript" ">" & Chr (13)
Response.Write "Alert (" "Please login First"); "& Chr (13)
Response.Write "History.go ( -1);" & Chr (13)
Response.Write "</script>" & Chr (13)
Else
' Initialize the inside of the shopping cart variable
P_id=trim (Request ("id"))
P_manu=trim (Request ("Manu"))
P_type=trim (Request ("type"))
P_name=replace (Trim (Request ("name1"), "", "")
P_price=trim (Request ("Price")
P_size=trim (Request ("size"))
P_color=trim (Request ("color")
P_num=trim (Request ("num")

if (not IsNumeric (p_num)) or (p_num<= "0") or (InStr (1,p_num, ".") <>0)) Then
P_num=1 ' If the quantity of goods is less than 0 or there are small points, take 1
End If

If P_name <> "" Then
' If you have a shopping cart, prepare to install it.
' If you don't have a shopping cart, create a new Dictionary object

If IsObject (Session ("Bag")) Then ' Update if a shopping cart is available
' Response.Write ' IsObject (Session ("Bag")) = "& IsObject (Session (" Bag ")) &" <br> "
Set Obj_bag=session ("Bag")
If Obj_bag.exists (p_name) Then ' if the item is already in the current cart
If Err Then
Response.Write Err.Description
Err.Clear
End If

' Response.Write IsObject (obj_bag)

P_temp=obj_bag.item (P_name) (6) ' stores P_num value in P_temp
Response.Write "p_num=" & P_num & "<br>"
P_num=cint (P_num) +cint (p_temp) ' quantity of goods purchased is cumulative

Bag_item=array (p_name,p_manu,p_type,p_size,p_color,p_price,p_num,p_id)
Obj_bag.item (P_name) =bag_item
Else
Bag_item=array (p_name,p_manu,p_type,p_size,p_color,p_price,p_num,p_id)
Obj_bag. ADD P_name,bag_item
End If

Else ' no shopping cart to generate new
Set Obj_bag=server. CreateObject ("Scripting.Dictionary")
Bag_item=array (p_name,p_manu,p_type,p_size,p_color,p_price,p_num,p_id)
Response.Write Bag_item (0)
Obj_bag. ADD P_name,bag_item
End If
Set session ("Bag") = Obj_bag ' Update cart
End If

Response.Redirect ("checkbag.asp?obj=" & Request ("obj") & "") ' Turn to show cart page
End If
%>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.