%
' Copyright (C) 1998-2005 CyberStrong Internet Services, Inc. All Rights Reserved
'
' This file has been seeded with unique information at point of sale and
' is traceable to its purchaser.
'
' Your license agreement forbids the removal of this notice.
%>
<%
'
' Review.asp - Display cart for customer review.
'
' Update the quantity and checked fields of the session shopping cart...
Dim i, iCount, SQL, rstItem, iSubTotal, s
Dim SplitArgs ' Holds the result of a split() call
Dim Description ' The short or expanded product description
Dim Status ' Status of user exit
Dim ReturnValue ' Return value from user exit
'Dim FormErrorMsg ' Holds errors for later form display
Dim MinQtyErrorMsg ' Holds errors for minimum quantity violations
Dim iPass ' 1 for first load, 2 for refresh
Dim ButtonPress ' The button pressed causing this load
' Lock cart out for maintenance ...
If (isLocked() Or (Not isDataBaseCurrent())) Then
Call DisplayMaintPage()
Response.End
End If
' GetFieldData() - Get field value from form ...
Public Function GetFieldData(ByVal FieldName, ByVal DemoValue)
Select Case True
Case (gblDemoMode AND iPass = 1) : GetFieldData = DemoValue
Case Else : GetFieldData = Request.Form(FieldName)
End Select
End Function
' UpdateCart() - Adjust quantities, remove deleted items.
Public Sub UpdateCart ()
Dim i, x, n, Quantity, UnitPrice
' This and next loop may not be combined, quantity changes
' will be lost.
If (iPass = 2) Then
' Adjust quantities, write-in prices, mark deleted items, total cart ...
For i = 1 to iCount
Quantity = Request("Quantity" & CStr(i))
If IsNumeric(Quantity) Then
aryCart(cartItemQuantity, i) = abs(CSng(Quantity))
Else
aryCart(cartItemQuantity, i) = CSng(1)
End If
If (cstAmountEditEnabled) Then
UnitPrice = Replace(Request("UnitPrice" & CStr(i)), "$", "")
If IsNumeric(UnitPrice) Then
aryCart(cartUnitPrice, i) = abs(CDbl(UnitPrice))
End If
End If
aryCart(cartTotalPrice, i) = aryCart(cartUnitPrice, i) * _
aryCart(cartItemQuantity, i)
' Flag user checked and discount line items for deletion ...
If (Request.Form("Keep" & CStr(i)) <> "y") Then
aryCart(cartDeleted, i) = "y"
End If
Next
End If ' (iPass = 2)
' Remove deleted items, slide following items down in array ...
For i = 1 to iCount
If ((aryCart(cartDeleted, i) = "y") OR _
(CStr(aryCart(cartItemQuantity, i)) = "0") OR _
(CStr(aryCart(cartItemType, i)) = "dsc") OR _
(CStr(aryCart(cartItemType, i)) = "cpn")) Then
iCount = iCount - 1
For x = 1 to UBound(aryCart, 1)
aryCart(x, i) = ""
Next
n = i
While n < UBound(aryCart, 2)
For x = 1 to UBound(aryCart, 1)
aryCart(x, n) = aryCart(x, n + 1)
aryCart(x, n + 1) = ""
Next
n = n + 1
Wend
i = i - 1
End If
Next
' Add earned discounts to cart ...
If (IsInstalled("Feature:Discounts") AND cstDiscountsEnabled) Then
FeatureInstalled("Feature:Discounts").AddToCart()
End If
' Add coupons tendered to cart ...
If (IsInstalled("Feature:Coupons") AND cstCouponsEnabled) Then
FeatureInstalled("Feature:Coupons").AddToCart()
End If
' User exit for pricing and quantity adjustment ...
Status = UserExit(usrAdjustCart, Conn, 0, 0, 0, ReturnValue)
' Save values to Session ...
Session(sesShoppingCart) = aryCart
Session(sesItemCount) = iCount
End Sub
' CheckMinQtys() - Check cart for mininum item requirements,
' Summarize order by product accross options
' to meet qty requirement ...
Public Sub CheckMinQtys()
Dim lstItems, aryProductList, aryQtyInfo(2), aryTemp, Key, aryKeys
' Omit check for min qty if this feature is disabled ...
If (Not cstMinOrderQtyEnabled) Then
Exit Sub
End If
' Indexes for aryQtyInfo()
Const idxMinQty = 0
Const idxTotalQty = 1
Const idxOptions = 2
' Build a summary of all products in the cart by qty ...
set lstItems = Server.CreateObject("Scripting.Dictionary")
MinQtyErrorMsg = ""
For i = 1 to iCount
' If this product exists in the dictionary, add
' customers order qty to it, otherwise, create this
' product in the dictionary.
Key = aryCart(cartProductCode, i)
If (lstItems.Exists(Key)) Then
aryTemp = lstItems.Item(Key)
aryTemp(idxTotalQty) = aryTemp(idxTotalQty) + CSng(aryCart(cartItemQuantity, i))
lstItems.Item(Key) = aryTemp
Else
aryQtyInfo(idxMinQty) = CSng(aryCart(cartMinQuantity, i))
aryQtyInfo(idxTotalQty) = CSng(aryCart(cartItemQuantity, i))
aryQtyInfo(idxOptions) = aryCart(cartOptions, i)
lstItems.Add Key, aryQtyInfo
End If
Next
' Cycle through summary, check min qtys ...
aryKeys = lstItems.Keys
For i = 0 To (lstItems.Count - 1)
If (lstItems.Item(aryKeys(i))(idxTotalQty) < lstItems.Item(aryKeys(i))(idxMinQty)) Then
MinQtyErrorMsg = MinQtyErrorMsg & _
" " & _
"The minimum order quantity for product " & aryKeys(i) & " is " & _
lstItems.Item(aryKeys(i))(idxMinQty) & ".
"
End If
Next
' Force purchase of minimum qtys on items that have no options ...
For i = 1 to iCount
If (aryCart(cartOptions, i) = "") Then
If (CSng(aryCart(cartItemQuantity, i)) < CSng(aryCart(cartMinQuantity, i))) Then
aryCart(cartItemQuantity, i) = aryCart(cartMinQuantity, i)
End If
End If
Next
' Clear the dictionary ...
lstItems.RemoveAll
' Release objects ...
set lstItems = Nothing
End Sub
' CalculateSubTotal() - Calculate subtotal to iSubTotal ...
Public Sub CalculateSubTotal()
iSubTotal = 0
For i = 1 to iCount
If ((aryCart(cartUnitPrice,i)) <> "") Then
iSubTotal = iSubtotal + aryCart(cartTotalPrice, i)
End If
Next
iSubTotal = IIF(iSubTotal < 0, 0, iSubTotal)
End Sub
' DisplayButtons() - Display action buttons ...
Public Sub DisplayButtons()
Dim rs
If (iCount < MaxShoppingCartItems) Then
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "Products", Conn, adOpenKeyset, adLockOptimistic
If (rs.RecordCount <> 1) Then
wl(" ")
End If
rs.Close
set rs = Nothing
End If
If (iCount > 0) Then
wl(" ")
End If
wl(" ")
If (iCount > 0) Then
wl(" ")
End If
End Sub
' ProductHasOptions() - Returns True if the given product code has options,
' Considers shared options as well.
Public Function ProductHasOptions(ByVal argProductCode)
Dim rs, SQL
ProductHasOptions = False
' Direct options ...
If (isOptionsAvail(GetURLValue("ProductCode"))) Then
ProductHasOptions = True
Exit Function
End If
If (cstSharedOptionsEnabled) Then
' Shared options ...
Set rs = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT OptionsUseProductCode FROM Products " & _
"WHERE ({fn UCASE(ProductCode)} = '" & CleanSQL(Ucase(argProductCode), "a") & "')"
rs.Open SQL, Conn, adOpenKeyset, adLockOptimistic
If (rs.RecordCount <> 0) Then
If (isOptionsAvail(rs("OptionsUseProductCode"))) Then
ProductHasOptions = True
End If
End If
rs.Close : Set rs = Nothing
End If
End Function
' isOptionsAvail() - Returns True if options are available and active for the given product code.
Public Function isOptionsAvail(ByVal argProductCode)
Dim rs, SQL
SQL = "SELECT DISTINCT Options.TypeID, OptionTypes.Active FROM Options " & _
"INNER JOIN OptionTypes ON Options.TypeID = OptionTypes.ID " & _
"WHERE ({fn LCASE(OptionTypes.Active)} <> 'no') AND " & _
" ({fn UCASE(Options.ProductCode)} = '" & CleanSQL(Ucase(argProductCode), "a") & "') " & _
"ORDER BY TypeID"
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open SQL, Conn, adOpenKeyset, adLockOptimistic
isOptionsAvail = CBool(rs.RecordCount <> 0)
rs.Close : Set rs = Nothing
End Function
' Main: ---------------------------------------------------------------------------------
FormErrorMsg = ""
iPass = 1
' Need this here, in the event that the 10Browse.asp module is not being used ...
If (Session(sesInit) = "") Then
Session("OrderID") = 0 ' For passing to thank you screen
Session(sesInit) = "True" ' Confirms that we are started
End If
' Create shopping cart if necessary ...
Call crtCreate()
' Confirm no session timeout ...
Call ConfirmSessionOk(sesItemCount)
' Recover session variables ...
If (Session(sesItemCount) <> "") Then
iCount = Session(sesItemCount)
aryCart = Session(sesShoppingCart)
End If
' Record customer's IP address and language now,
' as this info may be lost when the cart goes secure ...
Session("REMOTE_ADDR") = Request.ServerVariables("REMOTE_ADDR")
Session("HTTP_ACCEPT_LANGUAGE") = Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
' Open the database ...
Set Conn = dbOpen("rwl")
iPass = IIF(Request.Form("isFormPost") = "True", 2, 1)
Call UpdateCart()
Call CheckMinQtys()
' Process form events -------------------------------------------------
ButtonPress = LCase(GetFormAction())
SELECT CASE True
CASE ButtonPress = "continue"
If (FormErrorMsg = "") Then
Session(sesShoppingCart) = aryCart
Session(sesItemCount) = iCount
s = OurSession("ReturnTo")
OurSession("ReturnTo") = ""
If ((s <> "") AND (LCase(Left(s, 10)) <> "msetup.asp")) Then
dbClose(Conn)
Response.Redirect(s)
Else
OurSession("txtCategory") = Request.Form("txtCategory")
OurSession("txtSearchString") = Trim(Request.Form("txtSearchString"))
dbClose(Conn)
Response.Redirect(cstBrowseStartPageURL)
End If
End If
Call UpdateCart()
Call CheckMinQtys()
CASE ButtonPress = "recalculate"
Session(sesShoppingCart) = aryCart
Session(sesItemCount) = iCount
CASE ButtonPress = "cancelorder"
dbClose(Conn)
Session.Abandon
Response.Redirect(cstCancelURL)
CASE ButtonPress = "agree"
dbClose(Conn)
Response.Redirect("30GetCst.asp")
CASE ButtonPress = "checkout"
Call CalculateSubTotal()
If (CDbl(iSubTotal) < CDbl(cstMinOrderAmount)) Then
FormErrorMsg = FormErrorMsg & _
" " & _
"The minimum order for checkout is " & _
OurFormatCurrency(cstMinOrderAmount) & ".
"
End If
If ((FormErrorMsg & MinQtyErrorMsg) = "") Then
Session(sesItemCount) = iCount
Session(sesShoppingCart) = aryCart
dbClose(Conn)
If (iCount > 0) Then
' Display terms and conditions file if exists, or move to 30GetCst.asp ...
If (FileExists("Terms.htm")) Then
Call DisplayPageHeader("20", "", "")
wl("
| " & ReadFile("Terms.htm") & " |
| ") wl("") wl(" |