Chapter 24 Revisited: Dynamic Shipping Costs page 5
by
Tom Muck
8. Add a new script block BEFORE the current script
block that computes the cart values:
<%
' set the default shipping method to Standard, method 1, $4 per pound
Dim UCCart1_shippingMethodID
UCCart1_shippingMethodID = 1
Session("shippingConstant") = 4 'doesn't necessarily have
to be a session variable if you're only using it on this page
' if the user chose a different method by dropdown box, use that value
instead
If cstr(Request("shippingMethod"))<>"" Then
While (NOT rsShipping.EOF)
if (CStr(rsShipping.Fields.Item("ShippingMethodID").Value)
= CStr(Request("shippingMethod"))) then
Session("shippingConstant")
= rsShipping.Fields.Item("ShippingCostPerPound").Value
UCCart1_shippingMethodID = rsShipping.Fields.Item("ShippingMethodID").Value
End If
rsShipping.MoveNext()
Wend
If (rsShipping.CursorType > 0) Then
rsShipping.MoveFirst
Else
rsShipping.Requery
End If
End If
%>
<%'(old code)
Dim UCCart1_subTotal
Dim UCCart1_shippingCost
Dim UCCart1_totalPlusShipping
Dim UCCart1_salesTax
'...more code...
%>
10. In two places on the page you'll have to change the
hard-coded $4 per pound to the new session variable value:
In the script block that computes the cart values:
change this:
UCCart1_shippingCost = UCCart1.GetColumnTotal("TotalWeight")
* 4
to this:
UCCart1_shippingCost = UCCart1.GetColumnTotal("TotalWeight")
* Session("ShippingConstant")
and in the cart display on the page, change this:
x $4.00/lb
to this:
x <%=FormatCurrency(Session("ShippingConstant"))%>/lb
11. Add one hidden field to the first form, below the other
4 hidden fields that were coded in the original page. This new hidden
field will allow the shipping method ID number to be inserted into the
orders table:
<input type="hidden" name="uccartShippingMethodID"
value="<%=UCCart1_shippingMethodID%>">
12. Edit the Insert server behavior to include the new uccartShippingMethodID
form element and insert it into the shippingMethodID column of the Orders
table.
This completes the page, which should now allow the user
to change the shipping information, and have the changes reflected in
the orders table of the database, and also in the cart calculations.
<<< Previous HOME>>>
|