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

Week: 3 At a Glance > Day 20—Deleting Items from the Cart (checkout.asp)

Day 20—Deleting Items from the Cart (checkout.asp)

Deleting items from the shopping cart posed a challenge because the auto-generated UltraDev behavior has it's own agenda and will not work the way we want. The changes to this page (checkout.asp) involve removing UltraDev-generated code and eliminating the need for a server redirect.

<%@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 = ""
%> <%
' *** Delete Record: declare variables

if (CStr(Request("MM_delete")) <> "") Then

  MM_editConnection = MM_connCatalog_STRING
  MM_editTable = "tblCart"
  MM_editColumn = "cartID"
  MM_recordId = "" + Request.Form("MM_recordId") + ""
  MM_editRedirectUrl = ""

  ' set the redirect URL
  ' 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
%> <%
' *** Delete Record: construct a sql delete statement and execute it

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

  ' create the sql delete statement
  MM_editQuery = "delete from tblCart where cartID='" & Request("DeleteID") &
"'"

  If (Not MM_abortEdit) Then
    ' execute the delete
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.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")
%> <%
set rsCart = Server.CreateObject("ADODB.Recordset")
rsCart.ActiveConnection = MM_connCatalog_STRING
rsCart.Source = "SELECT
tblCart.cartID,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
%>
<%
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">
            <form name="frmDeleteFromCart" method="post"
action="<%=MM_editAction%>">
              <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>
                  <td><font face="Arial, Helvetica,
sans-serif"><b>Selected</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),
-1, -2, -2, -2) %></td>
                  <td>
                    <input type="radio" name="DeleteID"
value="<%=(rsCart.Fields.Item("cartID").Value)%>">
                  </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>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp; </td>
                  <td>
                    <input type="submit" name="Submit" value="Delete Selected
Item">
                  </td>
                </tr>
              </table>
              <input type="hidden" name="MM_delete" value="true">
            </form>
            <div align="center"><br>
              <a href="javascript:history.back()"><font face="Arial, Helvetica,
sans-serif">Continue
              Shopping</font></a><br>
              <br>
              <a href="checkout2.asp"><font face="Arial, Helvetica,
sans-serif">Go
              To Check Out</font></a></div>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>
<%
rsCart.Close()
%> <%
rsCartTotal.Close()
%>


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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