<% '************************************************************************* ' ASP Scripting: ' Filename: checkout_get_shipping_info.asp ' Written by: Wilbert Madarang ' Date: May 10, 2003 '************************************************************************* ' Description: '************************************************************************* ' Revision History: '************************************************************************* %> Charister.com - Checkout Get Shipping Info

1. Shipping Info      2. Order Review      3. Order Confirmation
<% Call PrintShoppingCartContents %> <% Call CalculateTotalBill %>
<% Call PrintTotalBill %>
<% Call PrintShoppingCartLinks %>
<% '************************************************************ ' Function: PrintShoppingCartContents ' Description: Prints the Shopping Cart contents ' Date: May 9, 2003 ' Written By: Wilbert Madarang '************************************************************ Function PrintShoppingCartContents Dim nNumItems, aryShoppingCart, nProductRegularPrice, nProductSalePrice, nProductPrice, nTotalPrice Dim strProductId, strProductCode, strProductName, strQuantity, strProductRegularPrice, strProductSalePrice, strProductColor Dim strCurrencyLabel 'Write Query Headers in Table Format Response.Write "" & vbCrLf Response.Write "
" & vbCrLf Response.Write "" & vbCrLf Response.Write "" & vbCrLf Response.Write "" & vbCrLf Response.Write "" & vbCrLf 'Print Shopping Cart Contents nNumItems = Session( "NumShopItems" ) aryShoppingCart = Session( "MyShoppingCart" ) For i = 1 to nNumItems 'strProductId = aryShoppingCart( i, SCART_PRODUCT_ID ) strProductCode = aryShoppingCart( i, SCART_PRODUCT_CODE ) strProductName = aryShoppingCart( i, SCART_PRODUCT_NAME ) strQuantity = aryShoppingCart( i, SCART_QUANTITY ) strProductRegularPrice = aryShoppingCart( i, SCART_REGULAR_PRICE ) strProductSalePrice = aryShoppingCart( i, SCART_SALE_PRICE ) strColor = aryShoppingCart( i, SCART_PRODUCT_COLOR ) 'Convert Numeric Variables strCurrencyLabel = GetCurrencyLabel() nQuantity = CInt( strQuantity ) nProductRegularPrice = CCur( strProductRegularPrice ) nProductSalePrice = CCur( strProductSalePrice ) nProductPrice = getProductPrice( nProductRegularPrice, nProductSalePrice ) nTotalPrice = nQuantity * nProductPrice 'Write Item Column Response.Write "" & vbCrLf Response.Write "" & vbCrLf 'Write Quantity Column Response.Write "" & vbCrLf 'Write Total Price Response.Write "" & vbCrLf Response.Write "" & vbCrLf Next Response.Write "
ItemsQtyTotal
" & vbCrLf Response.Write "" & strProductName & "
" & vbCrLf Response.Write "Price: " & strCurrencyLabel & FormatCurrency(strProductRegularPrice, 2) & "
" & vbCrLf If ( strProductSalePrice ) > 0 Then '******************************************** ' Added by WM, November 24, 2003 ' Added Red Color to Sale '******************************************** Response.Write "" & vbCrLf Response.Write "Sale: " & strCurrencyLabel & FormatCurrency(strProductSalePrice, 2) & "
" & vbCrLf Response.Write "
" & vbCrLf '******************************************** ' End of Addition by WM, Nov 24, 2003 '******************************************** End If If strColor = "" OR IsNull(strColor) Then Else Response.Write "Color: " & strColor & "
" & vbCrLf End If Response.Write "Product Code: " & strProductCode & "

" & vbCrLf Response.Write "
" & strQuantity & "
" & strCurrencyLabel & FormatCurrency( nTotalPrice, 2) & "
" & vbCrLf End Function '************************************************************ ' Function: CalculateTotalBill ' Description: Calculates the Total Bill ' Date: May 23, 2003 ' Written By: Wilbert Madarang '************************************************************ ' Modified by WM, September 28, 2003 ' 1.0 Subtotal Price broken down into: ' Subtotal Before Discounts ' Subtotal After Discounts ' 2.0 Modify GST, PST to Subtotal After Discounts '************************************************************ ' Modified by WM, November 8, 2003 ' 1.0 Modified Session("MyCountry") to Session("MyCurrency") '************************************************************ Function CalculateTotalBill Dim nSubTotalPrice, nSubTotalPriceBeforeDiscounts, nSubTotalPriceAfterDiscounts Dim nShippingRate, nPST, nGST, nPromoDiscount, nTotal Dim strDestCountry, strDestProvince, strCurrency Dim bFreeShipping 'Determine the Shipping Coordinates ... strDestCountry = Session("MyShippingCountry") strDestProvince = Session("MyShippingProvince") strCurrency = Session("MyCurrency") 'Populate Fields 'nSubTotalPrice = getShoppingCartSubtotal() 'bFreeShipping = checkFreeShipping( nSubTotalPrice, strCurrency ) 'nShippingRate = getShippingRates( nSubTotalPrice, strDestCountry, strCurrency ) nSubTotalPriceBeforeDiscounts = getShoppingCartSubtotal() 'bFreeShipping = checkFreeShipping( nSubTotalPriceBeforeDiscounts, strCurrency ) nShippingRate = getShippingRates( nSubTotalPriceBeforeDiscounts, strDestCountry, strCurrency ) 'If Free Shipping If (bFreeShipping = True) Then nPromoDiscount = nShippingRate Else 'nPromoDiscount = getPromoDiscount( nSubTotalPrice ) nPromoDiscount = getPromoDiscount( nSubTotalPriceBeforeDiscounts ) End If 'nPST = getPST( nSubTotalPrice, strDestProvince, strDestCountry ) 'nGST = getGST( nSubTotalPrice, strDestProvince, strDestCountry ) 'nTotal = nSubTotalPrice + nShippingRate + nPST + nGST - nPromoDiscount nSubTotalPriceAfterDiscounts = nSubTotalPriceBeforeDiscounts - nPromoDiscount + nShippingRate nPST = getPST( nSubTotalPriceAfterDiscounts, strDestProvince, strDestCountry ) nGST = getGST( nSubTotalPriceAfterDiscounts, strDestProvince, strDestCountry ) nTotal = nSubTotalPriceAfterDiscounts + nPST + nGST 'Store into Session Variables 'Session( "MySubTotal" ) = nSubTotalPrice Session( "MySubTotalBeforeDiscounts" ) = nSubTotalPriceBeforeDiscounts Session( "MySubTotalAfterDiscounts" ) = nSubTotalPriceAfterDiscounts Session( "MyShippingCost" ) = nShippingRate Session( "MyPromoDiscount" ) = nPromoDiscount Session( "MyPST" ) = nPST Session( "MyGST" ) = nGST Session( "MyTotal" ) = nTotal End Function '************************************************************ ' Function: PrintTotalBill ' Description: Prints the Total Bill ' Date: May 23, 2003 ' Written By: Wilbert Madarang '************************************************************ Function PrintTotalBill Dim nSubTotalPrice, nSubTotalPriceBeforeDiscounts, nSubTotalPriceAfterDiscounts Dim nShippingRate, nPST, nGST, nPromoDiscount, nTotal 'Retrieve Session Variables 'nSubTotalPrice = Session( "MySubTotal" ) nSubTotalPriceBeforeDiscounts = Session( "MySubTotalBeforeDiscounts" ) nSubTotalPriceAfterDiscounts = Session( "MySubTotalAfterDiscounts" ) nShippingRate = Session( "MyShippingCost" ) nPromoDiscount = Session( "MyPromoDiscount" ) nPST = Session( "MyPST" ) nGST = Session( "MyGST" ) nTotal = Session( "MyTotal" ) 'Print out SubTotal 'Response.Write "Subtotal is " & strCurrencyLabel & FormatCurrency( nSubTotalPrice, 2 ) & "
" & vbCrLf Response.Write "Subtotal " & strCurrencyLabel & FormatCurrency( nSubTotalPriceBeforeDiscounts, 2 ) & "
" & vbCrLf Response.Write "Promotional Discount (" & strCurrencyLabel & FormatCurrency(nPromoDiscount,2) & ")
" & vbCrLf Response.Write "Shipping and Handling Fee " & FormatCurrency( nShippingRate, 2 ) & "
" & vbCrLf Response.Write "
" & vbCrLf Response.Write "Subtotal (after discount and shipping) " & strCurrencyLabel & FormatCurrency( nSubTotalPriceAfterDiscounts, 2 ) & "
" & vbCrLf Response.Write "PST " & FormatCurrency( nPST, 2) & "
" & vbCrLf Response.Write "GST " & FormatCurrency( nGST, 2) & "
" & vbCrLf Response.Write "Total " & FormatCurrency( nTotal, 2) & "
" & vbCrLf End Function '************************************************************ ' Function: PrintShoppingCartLinks ' Description: Prints the Shopping Cart Links ' Date: May 18, 2003 ' Written By: Wilbert Madarang '************************************************************ Function PrintShoppingCartLinks strShoppingCartUrl = "view_shopping_cart.asp" 'Response.Write "RETURN TO SHOPPING CART" & vbCrLf Response.Write "" & vbCrLf Response.Write "" & vbCrLf Response.Write "" & vbCrLf 'Response.Write "CHECKOUT SUBMIT ORDER" & vbCrLf Response.Write "" & vbCrLf Response.Write "" & vbCrLf Response.Write "
" & vbCrLf Response.Write "
" & vbCrLf Response.Write "
" & vbCrLf Response.Write "
" & vbCrLf Response.Write "
" & vbCrLf End Function '************************************************************ ' Function: checkFreeShipping ' Description: Checks if Free Shipping Criteria is Met ' Date: June 21, 2003 ' Written By: Wilbert Madarang '************************************************************ Function checkFreeShipping( nSubTotalPrice, strCurrency ) Dim nMinimumAmount 'Minimum Amount required to Qualify for Free Shipping Dim bFreeShipping bFreeShipping = False 'Check if FreeShipping Promo Code has been Entered If Session( "MyPromoCodeFreeShipping" ) = True Then 'Retrieve the Minimum Amount Required to Qualify for Free Shipping If strCurrency = "canada" Then nMinimumAmount = PROMO_CODE_FREE_SHIPPING_MINIMUM_AMOUNT_CDN Elseif strCurrency = "us" Then nMinimumAmount = PROMO_CODE_FREE_SHIPPING_MINIMUM_AMOUNT_US End If 'Compare SubTotal and Minimum Amount If (nSubTotalPrice >= nMinimumAmount) Then bFreeShipping = True End If End If checkFreeShipping = bFreeShipping End Function '************************************************************ ' Function: getPromoDiscount ' Description: Obtain the Promotional Discount ' Date: June 21, 2003 ' Written By: Wilbert Madarang '************************************************************ Function getPromoDiscount( nSubTotalPrice ) Dim nPromoDiscount Dim nPercentage, bFreeShipping nPromoDiscount = 0 If Session("MyPromoCodeIsValid")=True Then 'Check if Promo is Free Shipping If Session("MyPromoCodeFreeShipping")=False Then nPercentage = Session( "MyPromoCodeValue" ) nPromoDiscount = nSubTotalPrice * (nPercentage/100) End If End If getPromoDiscount = nPromoDiscount End Function '************************************************************ ' Function: getShippingRates ' Description: gets the Shipping Rate ' Date: May 23, 2003 ' Written By: Wilbert Madarang '************************************************************ ' Modified: November 10, 2003 ' Modified DB so that ShippingRates also ' include Currency '************************************************************ Function getShippingRates( nSubTotalPrice, strDestination, strCurrency ) Dim strSQL, strTable, strConstraint Dim nShippingRate 'Initialize Amount to Zero nShippingRate = 0 'Retrieve From Database strConstraint = " WHERE destination='" & strDestination &_ "' AND (minRange < " & CStr(nSubTotalPrice) & ") AND (" & CStr(nSubTotalPrice) & " <= maxRange) " & _ " AND currency='" & strCurrency & "'" strTable = " dirShippingRates " strSQL = "SELECT * FROM " & strTable & strConstraint Call openDataConnection() Set rs = dataConnection.Execute( strSQL ) Call closeDataConnection() 'Retrive Shipping Rate If NOT rs.EOF Then ' If strCurrency = "canada" Then ' nShippingRate = rs.Fields( "shippingRateCdn" ) ' Elseif strCurrency = "us" Then ' nShippingRate = rs.Fields( "shippingRateUS" ) ' Else ' nShippingRate = rs.Fields( "shippingRateUS" ) ' End If nShippingRate = rs.Fields( "shippingRate" ) End If getShippingRates = CCur( nShippingRate ) End Function '************************************************************ ' Function: getPST ' Description: get the PST amount ' Date: May 23, 2003 ' Written By: Wilbert Madarang '************************************************************ Function getPST( nSubTotalPrice, strDestProvince, strDestCountry ) Dim nPST Dim PST_RATE nPST = 0 PST_RATE = 0.08 If (strDestProvince = "ontario") OR (strDestProvince="Ontario") Then nPST = PST_RATE * nSubTotalPrice End If getPST = nPST End Function '************************************************************ ' Function: getGST ' Description: get the GST amount ' Date: May 23, 2003 ' Written By: Wilbert Madarang '************************************************************ Function getGST( nSubTotalPrice, strDestProvince, strDestCountry ) Dim nGST Dim GST_RATE nGST = 0 'ay071906 change GST from 7% to 6%, from 6% to 5% ' GST_RATE = 0.07 ' GST_RATE = 0.06 GST_RATE = 0.05 If (strDestCountry = "canada") OR (strDestProvince="Canada") Then nGST = GST_RATE * nSubTotalPrice End If getGST = nGST End Function '************************************************************** ' FUNCTION: getOrderNumber ' DESCRIPTION: Generate Order Number for Transaction ' PARAMETERS: none ' RETURNS: none '************************************************************** Function getOrderNumber( nNumberOfDigits ) Dim floatRandomNumber, nRandomNumber Dim nMaxNumber Dim strOrderNumber 'Make sure Number of Digits is Valid If ( nNumberOfDigits <= 0 ) Then nNumberOfDigits = DEFAULT_ORDER_NUMBER_SIZE End If 'Maximum Number of Digits Randomize() nMaxNumber = 10^nNumberOfDigits floatRandomNumber = nMaxNumber * Rnd() nRandomNumber = Int( floatRandomNumber ) strOrderNumber = CStr( nRandomNumber ) & "-" & _ Month(Date) & _ Day(Date) & _ Year(Date) getOrderNumber = strOrderNumber End Function %>