• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Week: 3 At a Glance > Day 20—Final Checkout (checkout2.asp)

Day 20—Final Checkout (checkout2.asp)

The final checkout process for the e-commerce site rewrites the temporary shopping cart so that it is considered finished. This is a completely unique behavior to this application and is not directly based on an existing UltraDev behavior.

<%@LANGUAGE="VBSCRIPT"%> <!--#include file="../Connections/connCatalog.asp" -->
<%
' *** Edit Operations: declare variables

MM_editAction = CStr(Request("URL"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%> <%
' *** Insert Record: set variables
If (CStr(Request("MM_insert")) <> "") Then

  MM_editConnection = MM_connCatalog_STRING
  MM_editTable = "tblOrderInfo"
  MM_editRedirectUrl = "finished.asp"
  MM_fieldsStr  =
"shipaddress1|value|shipaddress2|value|shipcity|value|shipstate|value|shipzip|value|billaddress1|value|billaddress2|value|billcity|value|billstate|value|billzip|value|paymethod|value|payaccount|value|payexpire|value"
  MM_columnsStr =
"shipaddress1|',none,''|shipaddress2|',none,''|shipcity|',none,''|shipstate|',none,''|shipzip|',none,''|billaddress1|',none,''|billaddress2|',none,''|billcity|',none,''|billstate|',none,''|billzip|',none,''|paymethod|',none,''|payaccount|',none,''|payexpire|',none,''"

  ' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")

  ' set the form values
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
  Next

  ' set the redirect URL
  If (MM_editRedirectUrl = "") Then
    MM_editRedirectUrl = CStr(Request("URL"))
  End If
  If (Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And
Request.QueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
  End If

End If
%> <%
' *** Insert Record: construct a sql insert statement and execute it

If (CStr(Request("MM_insert")) <> "") Then

  ' create the sql insert statement
  MM_tableValues = ""
  MM_dbValues = ""
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    FormVal = MM_fields(i+1)
    MM_typeArray = Split(MM_columns(i+1),",")
    Delim = MM_typeArray(0)
    If (Delim = "none") Then Delim = ""
    AltVal = MM_typeArray(1)
    If (AltVal = "none") Then AltVal = ""
    EmptyVal = MM_typeArray(2)
    If (EmptyVal = "none") Then EmptyVal = ""
    If (FormVal = "") Then
      FormVal = EmptyVal
    Else
      If (AltVal <> "") Then
        FormVal = AltVal
      ElseIf (Delim = "'") Then  ' escape quotes
        FormVal = "'" & Replace(FormVal,"'","''") & "'"
      Else
        FormVal = Delim + FormVal + Delim
      End If
    End If
    If (i <> LBound(MM_fields)) Then
      MM_tableValues = MM_tableValues & ","
      MM_dbValues = MM_dbValues & ","
    End if
    MM_tableValues = MM_tableValues & MM_columns(i)
    MM_dbValues = MM_dbValues & FormVal
  Next
  orderStr=Date()&"-"&Session("MM_Username")&"-"&Time()
  MM_editQuery = "insert into " & MM_editTable & " (orderID," & MM_tableValues &
") values ('" & orderStr & "'," & MM_dbValues & ")"

  If (Not MM_abortEdit) Then
    ' execute the insert
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute

    ' Modify the order items to have the same ID
    Set FixOrder = Server.CreateObject("ADODB.Command")
    FixOrder.ActiveConnection = MM_editConnection
    FixOrder.CommandText = "UPDATE tblCart SET orderID='" & orderStr & "' WHERE
username='" & Session("MM_Username") & "' AND orderID=''"
    FixOrder.Execute

    If (MM_editRedirectUrl <> "") Then
      Call Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>
<%
Dim rsCart__varUsername
rsCart__varUsername = "testuser"
if (Session("MM_Username")  <> "") then rsCart__varUsername =
Session("MM_Username")
%> <%
Dim rsCartTotal__varUsername
rsCartTotal__varUsername = "testuser"
if (Session("MM_Username")  <> "") then rsCartTotal__varUsername =
Session("MM_Username")
%> <%
Dim rsUserInfo__varUsername
rsUserInfo__varUsername = "testuser"
if (Session("MM_Username")  <> "") then rsUserInfo__varUsername =
Session("MM_Username")
%> <%
set rsCart = Server.CreateObject("ADODB.Recordset")
rsCart.ActiveConnection = MM_connCatalog_STRING
rsCart.Source = "SELECT tblCart.prodID,tblProduct.prodName,tblProduct.ProdPrice
FROM tblCart,tblProduct  WHERE tblCart.username='" + Replace(rsCart__varUsername,
"'", "''") + "' AND tblCart.prodID=tblProduct.prodID AND tblCart.orderID=''"
rsCart.CursorType = 0
rsCart.CursorLocation = 2
rsCart.LockType = 3
rsCart.Open()
rsCart_numRows = 0
%>
<%
set rsCartTotal = Server.CreateObject("ADODB.Recordset")
rsCartTotal.ActiveConnection = MM_connCatalog_STRING
rsCartTotal.Source = "SELECT sum(tblProduct.ProdPrice)  FROM tblCart,tblProduct
WHERE tblCart.username='" + Replace(rsCartTotal__varUsername, "'", "''") + "' AND
tblCart.prodID=tblProduct.prodID AND tblCart.orderID=''"
rsCartTotal.CursorType = 0
rsCartTotal.CursorLocation = 2
rsCartTotal.LockType = 3
rsCartTotal.Open()
rsCartTotal_numRows = 0
%>
<%
set rsUserInfo = Server.CreateObject("ADODB.Recordset")
rsUserInfo.ActiveConnection = MM_connCatalog_STRING
rsUserInfo.Source = "SELECT *  FROM tblUserInfo  WHERE username='" +
Replace(rsUserInfo__varUsername, "'", "''") + "'"
rsUserInfo.CursorType = 0
rsUserInfo.CursorLocation = 2
rsUserInfo.LockType = 3
rsUserInfo.Open()
rsUserInfo_numRows = 0
%>
<%
set rsOrderInfo = Server.CreateObject("ADODB.Recordset")
rsOrderInfo.ActiveConnection = MM_connCatalog_STRING
rsOrderInfo.Source = "SELECT *  FROM tblOrderInfo"
rsOrderInfo.CursorType = 0
rsOrderInfo.CursorLocation = 2
rsOrderInfo.LockType = 3
rsOrderInfo.Open()
rsOrderInfo_numRows = 0
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
rsCart_numRows = rsCart_numRows + Repeat1__numRows
%>
<html>
<head>
<title>Catalog</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFCC" leftmargin="0" topmargin="0" marginwidth="0"
marginheight="0">
<table width="650" border="0" cellpadding="5" cellspacing="0">
  <tr bgcolor="#000066">
    <td width="15%" bgcolor="#CCCCFF">&nbsp;</td>
    <td width="85%" align="center"><font face="Arial, Helvetica, sans-serif"
size="6" color="#FFFFFF">Shopping
      Cart </font></td>
  </tr>
  <tr>
    <td width="15%" bgcolor="#CCCCFF" valign="top">
      <p><b><font face="Arial, Helvetica, sans-serif">Product
Categories:</font></b></p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
    </td>
    <td width="85%" valign="top" bgcolor="#FFCC99">
      <table width="100%" border="0" cellspacing="0" cellpadding="50">
        <tr valign="top" align="left">
          <td height="304">
            <table width="100%" border="0" cellspacing="0" cellpadding="2">
              <tr>
                <td><font face="Arial, Helvetica, sans-serif"><b>Product
ID</b></font></td>
                <td><font face="Arial, Helvetica,
sans-serif"><b>Name</b></font></td>
                <td><font face="Arial, Helvetica,
sans-serif"><b>Price</b></font></td>
              </tr>
              <%
While ((Repeat1__numRows <> 0) AND (NOT rsCart.EOF))
%>
              <tr>
                <td><%=(rsCart.Fields.Item("prodID").Value)%></td>
                <td><%=(rsCart.Fields.Item("prodName").Value)%></td>
                <td><%= FormatCurrency((rsCart.Fields.Item("ProdPrice").Value),
2, -2, -2, -2) %></td>
              </tr>
              <%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsCart.MoveNext()
Wend
%>
              <tr>
                <td>&nbsp;</td>
                <td><b><font face="Arial, Helvetica,
sans-serif">Total:</font></b></td>
                <td><%=
FormatCurrency((rsCartTotal.Fields.Item("sum(tblProduct.ProdPrice)").Value), -1,
-2, -2, -2) %></td>
              </tr>
            </table>
            <div align="center"><br>
              <form ACTION="<%=MM_editAction%>" name="frmFinalOrder"
method="POST">
                <table width="100%" border="0" cellspacing="0" cellpadding="2">
                  <tr align="center" bgcolor="#FFFFCC">
                    <td colspan="2"><b><font face="Arial, Helvetica,
sans-serif">Shipping
                      Info</font></b></td>
                  </tr>
                  <tr>
                    <td width="25%"><font face="Arial, Helvetica, sans-serif">
                      Address 1:</font></td>
                    <td width="75%">
                      <input type="text" name="shipaddress1" size="50"
value="<%=(rsUserInfo.Fields.Item("address1").Value)%>">
                    </td>
                  </tr>
                  <tr>
                    <td width="25%"><font face="Arial, Helvetica, sans-serif">
                      Address 2:</font></td>
                    <td width="75%">
                      <input type="text" name="shipaddress2" size="50"
value="<%=(rsUserInfo.Fields.Item("address2").Value)%>">
                    </td>
                  </tr>
                  <tr>
                    <td width="25%"><font face="Arial, Helvetica,
sans-serif">City:</font></td>
                    <td width="75%">
                      <input type="text" name="shipcity"
value="<%=(rsUserInfo.Fields.Item("city").Value)%>">
                    </td>
                  </tr>
                  <tr>
                    <td width="25%"><font face="Arial, Helvetica,
sans-serif">State:</font></td>
                    <td width="75%">
                      <input type="text" name="shipstate"
value="<%=(rsUserInfo.Fields.Item("state").Value)%>">
                    </td>
                  </tr>
                  <tr>
                    <td width="25%">
                      <p><font face="Arial, Helvetica,
sans-serif">Zip:</font></p>
                    </td>
                    <td width="75%">
                      <input type="text" name="shipzip"
value="<%=(rsUserInfo.Fields.Item("zip").Value)%>">
                    </td>
                  </tr>
                  <tr bgcolor="#FFFFCC">
                    <td colspan="2">
                      <div align="center"><b><font face="Arial, Helvetica,
sans-serif">Billing
                        Info </font></b></div>
                    </td>
                  </tr>
                  <tr>
                    <td width="25%"><font face="Arial, Helvetica,
sans-serif">Address
                      1:</font></td>
                    <td width="75%">
                      <input type="text" name="billaddress1" size="50"
value="<%=(rsUserInfo.Fields.Item("address1").Value)%>">
                    </td>
                  </tr>
                  <tr>
                    <td width="25%"><font face="Arial, Helvetica,
sans-serif">Address
                      2:</font></td>
                    <td width="75%">
                      <input type="text" name="billaddress2" size="50"
value="<%=(rsUserInfo.Fields.Item("address2").Value)%>">
                    </td>
                  </tr>
                  <tr>
                    <td width="25%"><font face="Arial, Helvetica,
sans-serif">City:</font></td>
                    <td width="75%">
                      <input type="text" name="billcity"
value="<%=(rsUserInfo.Fields.Item("city").Value)%>">
                    </td>
                  </tr>
                  <tr>
                    <td width="25%"><font face="Arial, Helvetica,
sans-serif">State:</font></td>
                    <td width="75%">
                      <input type="text" name="billstate"
value="<%=(rsUserInfo.Fields.Item("state").Value)%>">
                    </td>
                  </tr>
                  <tr>
                    <td width="25%"><font face="Arial, Helvetica,
sans-serif">Zip:</font></td>
                    <td width="75%">
                      <input type="text" name="billzip"
value="<%=(rsUserInfo.Fields.Item("zip").Value)%>">
                    </td>
                  </tr>
                  <tr>
                    <td width="25%">&nbsp;</td>
                    <td width="75%">&nbsp;</td>
                  </tr>
                  <tr>
                    <td width="25%"><font face="Arial, Helvetica,
sans-serif">Payment
                      Method:</font></td>
                    <td width="75%">
                      <select name="paymethod">
                        <option selected>Mastercard</option>
                        <option>Visa</option>
                      </select>
                    </td>
                  </tr>
                  <tr>
                    <td width="25%"><font face="Arial, Helvetica,
sans-serif">Account
                      Number:</font></td>
                    <td width="75%">
                      <input type="text" name="payaccount">
                    </td>
                  </tr>
                  <tr>
                    <td width="25%"><font face="Arial, Helvetica,
sans-serif">Expiration
                      Date:</font></td>
                    <td width="75%">
                      <input type="text" name="payexpire">
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2">
                      <div align="center">
                        <input type="submit" name="Submit" value="Submit Order">
                      </div>
                    </td>
                  </tr>
                </table>
                <input type="hidden" name="MM_insert" value="true">
              </form>
            </div>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>
<%
rsCart.Close()
%> <%
rsCartTotal.Close()
%> <%
rsUserInfo.Close()
%> <%
rsOrderInfo.Close()
%>


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint