on error resume next Response.Buffer = true Response.Expires = 0 dim obj_bag,bag_item,cart 'obj_bag ----購物車 'bag_item ----商品的信息數據集合 'cart ----一件商品的信息數據集合 dim p_id,p_name,p_
if ((not IsNumeric(p_num)) or (p_num<="0") or (instr(1,p_num,".")<>0)) then p_num=1 ‘如果商品數量小于0或者有小數點,取1 end if
if p_name <>"" then '如果有購物信息傳入則準備裝如購物車 '如果還沒有購物車則新建dictionary對象
if isobject(Session("Bag")) then '如果有購物車則更新 'response.write "isobject(Session(""Bag""))=" & isobject(Session("Bag")) & "<br>" set obj_bag=Session("Bag") if obj_bag.exists(p_name) then ''如果當前購物車中已有該商品 if err then response.write err.description err.clear end if
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 '沒有購物車生成新的 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 '更新購物車 end if
Response.Redirect ("checkbag.asp?obj="& request("obj") &"") '轉向顯示購物車頁面 end if %>