Page 20 of 22 - Chapter 14
Roll with it - Degrading Gracefully When It All Goes Wrong (cont'd)
We are only informing the user of problem items so if there are sufficient
available we just create the hidden form elements for ItemId and quantity. The
loop continues though each item.
// If insufficent stock
if (iQtyInStock < iQty)
{
// no stock at all - so no able to provide any of this item
if (iQtyInStock == 0)
{
%>
<P><STRONG>
<%= loRS("Title") %> by <%= loRS("ArtistName")
%> is currently
unavailable, we hope to have new stock in shortly
</STRONG></P>
<%
}
else
// some stock available but not enough
{
%>
<P>
<STRONG>
You requested <%= iQty %> copies of <%= loRS("Title")
%> by
<%= loRS("ArtistName") %>, but unfortunately
we only have
<%= iQtyInStock %> in stock
</STRONG>
<INPUT TYPE="Hidden" NAME="<%= "txtID"
+ iItemId %>"
VALUE="<%= "ID" + iItemId %>">
<INPUT TYPE="Hidden" NAME="<%= "txtQtyID"
+ iItemId %>"
VALUE="<%= iQtyInStock %>">
</P>
<%
}
}
else
// sufficent stock - add hidden elements to form
{
%>
<INPUT TYPE="Hidden" NAME="<%= "txtID"
+ iItemId %>"
VALUE="<%= "ID" + iItemId %>">
<INPUT TYPE="Hidden" NAME="<%= "txtQtyID"
+ iItemId %>"
VALUE="<%= iQtyInStock %>">
<%
}
}
}
%> |
Finally we add two buttons giving the customer the choice of continuing with
the available amounts or canceling altogether.
<P>
Click <INPUT TYPE="Submit" NAME="cmdSubmit"
VALUE="Process Order">
to submit your order with the maximum amount amounts available.
</P>
<P>
Click <INPUT TYPE="button" NAME="cmdCancel"
VALUE="Cancel Order"
onClick="window.location.replace('ordercancel.htm');">
to end this transaction, no monies have been debited from your
credit card.
</P>
</FORM>
<%
}
// close database connection
loConn.Close();
loConn = null;
%>
</BODY>
</HTML> |
We have completed this page so re-save the file before closing it and continuing.
The OrderCancel and TransactionError Pages
Let's take the ordercancel.htm page first. Here we inform the user that no
money has been debited from their card and give them the option to continue
shopping.
<HTML>
<BODY>
<DIV ALIGN="center">
<FONT FACE="Comic Sans MS" SIZE="4">
Your order has been cancelled successfully.<br>
No monies will be deducted from your credit card
</FONT>
<FORM ACTION="" method="POST">
<INPUT TYPE="button" NAME="cmdMainPage" VALUE="Continue
shopping"
onClick="top.location.replace('musicmad.htm')">
</FORM>
</DIV>
</BODY>
</HTML> |
Save the page as ordercancel.htm before continuing.
For the transerror.asp page we reassure them that no money has been debited
and will also display the error message, more for our benefit when trying to
debug. The actual error description was passed in the URL by the OnTransactionAbort
method of the processorder.asp page which redirected us here.
<!--#include file="ServerSideGlobalDef.inc"-->
<%
var sErrorDescription = unescape(Request.QueryString);
%>
<HTML>
<HEAD></HEAD>
<BODY>
<FONT FACE="Comic Sans MS" SIZE="3">
Due to a technical fault we have been unable to complete your
order.<BR>
Your order has been cancelled and no monies will be deducted from your
credit card.<BR>
The problem is listed below
</FONT>
<BR>
<P><%= sErrorDescription %></P>
</BODY>
</HTML> |
This page needs to be saved as transerror.asp.