<% dim rs, rsSpecial, rsLineItem, rsSpecProd, rsCheck, rsUpsell dim rsShipMethod, rsShipping dim product, special dim strSQL dim order_id, cart_id dim qty dim rsCartId dim emptyCart dim line_no dim total_products dim special_product_count dim redir dim upsell_product dim temp_product_id, temp_upsell_id dim special_qty dim ship_method, shippingCost qty = 1 special_qty = 0 product = GetRequestInteger("prod") special = GetRequestString("special") If special = "true" Then special_qty = 1 End If redir = "viewitems.htm" Call connectDB If Len(Session("CartId")) = 0 Then strSQL = "usp_Ins_Cart null, null, null " ' strSQL = strSQL & Session("CustId") con.Execute(strSQL) Set rsCartId = server.CreateObject("ADODB.RecordSet") rsCartId.ActiveConnection = con rsCartId.Open("SELECT @@identity FROM Cart") Session("CartId") = rsCartId(0) rsCartId.Close Set rsCartId = nothing End If cart_id = Session("CartId") Call CheckRequestInteger(cart_id) strSQL = "SELECT cartitem_line_no, cartitem_qty FROM CartItem " strSQL = strSQL & "WHERE cart_id = " & cart_id strSQL = strSQL & "AND product_id = " & product Set rsCheck = Server.CreateObject("ADODB.RecordSet") rsCheck.ActiveConnection = con rsCheck.CursorLocation = 3 rsCheck.CursorType = 0 rsCheck.LockType = 1 rsCheck.Open(strSQL) If not rsCheck.EOF Then 'Product is in the cart. Update the qty 'strSQL = "UPDATE CartItem Set " 'strSQL = strSQL & "cartitem_qty = cartitem_qty + 1 " 'strSQL = strSQL & "WHERE cart_id = " & cart_id 'strSQL = strSQL & " AND product_id = " & product 'con.execute(strSQL) strSQL = "usp_Upd_CartItem " strSQL = strSQL & cart_id & ", " strSQL = strSQL & rsCheck("cartitem_line_no") & ", " strSQL = strSQL & rsCheck("cartitem_qty") + qty con.Execute(strSQL) Else 'Add the cart item strSQL = "usp_Ins_CartItem " strSQL = strSQL & cart_id & ", " strSQL = strSQL & product & ", " strSQL = strSQL & qty con.Execute(strSQL) strSQL = "SELECT MAX(cartitem_line_no) FROM CartItem WHERE cart_id = " & cart_id Set rs = Server.CreateObject("ADODB.RecordSet") rs.ActiveConnection = con rs.CursorLocation = 3 rs.CursorType = 0 rs.LockType = 1 rs.Open(strSQL) temp_product_id = rs(0) rs.Close Set rs = nothing strSQL = "SELECT product_id FROM ProductSpecial WHERE required_product_id = " & product Set rsUpsell = Server.CreateObject("ADODB.RecordSet") rsUpsell.ActiveConnection = con rsUpsell.CursorLocation = 3 rsUpsell.CursorType = 0 rsUpsell.LockType = 1 rsUpsell.Open(strSQL) If not rsUpsell.EOF Then upsell_product = rsUpsell(0) strSQL = "usp_Ins_CartItem " strSQL = strSQL & cart_id & ", " strSQL = strSQL & upsell_product & ", " strSQL = strSQL & special_qty con.Execute(strSQL) 'Response.Write(strSQL) 'Response.End strSQL = "SELECT MAX(cartitem_line_no) FROM CartItem WHERE cart_id = " & cart_id Set rsLineItem = Server.CreateObject("ADODB.RecordSet") rsLineItem.ActiveConnection = con rsLineItem.CursorLocation = 3 rsLineItem.CursorType = 0 rsLineItem.LockType = 1 rsLineItem.Open(strSQL) strSQL = "UPDATE CartItem SET cartitem_upsell_line_no = " & rsLineItem(0) strSQL = strSQL & " WHERE cartitem_line_no = " & temp_product_id strSQL = strSQL & " AND cart_id = " & cart_id con.execute(strSQL) rsLineItem.Close Set rsLineItem = nothing End If rsUpsell.Close Set rsUpsell = nothing End if rsCheck.Close Set rsCheck = nothing 'Update the shipping costs if they have already selected a shipping method '----------------------------- strSQL = "SELECT ship_method_id FROM Cart WHERE cart_id = " & cart_id Set rsShipMethod = Server.CreateObject("ADODB.RecordSet") rsShipMethod.ActiveConnection = con rsShipMethod.CursorLocation = 3 rsShipMethod.CursorType = 0 rsShipMethod.LockType = 1 rsShipMethod.Open(strSQL) If not isNull(rsShipMethod(0)) Then ship_method = rsShipMethod(0) Else ship_method = "" End If rsShipMethod.Close Set rsShipMethod = nothing If len(ship_method & "") > 0 Then 'Update the shipping costs if they have already select a shipping method strSQL = "SELECT sum(cartitem_ship_charge) FROM Product p " strSQL = strSQL & "JOIN CartItem c ON p.product_id = c.product_id " strSQL = strSQL & "WHERE cart_id = " & cart_id strSQL = strSQL & " AND product_special_yn = 'N'" Set rsShipping = Server.CreateObject("ADODB.RecordSet") rsShipping.ActiveConnection = con rsShipping.CursorLocation = 3 rsShipping.CursorType = 0 rsShipping.LockType = 1 rsShipping.Open(strSQL) If ship_method = 1 Then shippingCost = rsShipping(0) ElseIf ship_method = 2 Then shippingCost = 14.99 End if rsShipping.Close Set rsShipping = nothing strSQL = "UPDATE Cart SET " strSQL = strSQL & "cart_ship_charge_amt = " & Round(shippingCost,2) strSQL = strSQL & " WHERE cart_id = " & cart_id con.execute(strSQL) End If con.close Set con = nothing Response.Redirect(redir) %>