Cartweaver Debugger
"
cwDebugOutput = cwDebugOutput & strDebugOutput
cwDebugOutput = cwDebugOutput & "Page execution time: " & Timer - TickCount & " s"
'Output all built-in Cartweaver variables
cwDebugOutput = cwDebugOutput & "
Built-in Cartweaver Variables
"
Dim arVarList, strVarList
arVarList = "websiteURL,websiteSSLURL,onSubmitAction,targetResults,recordsAtATime,targetDetails," &_
"detailsDisplay,targetGoToCart,targetCheckout,targetConfirmOrder,cwLocale,uploadCom,mailObj," &_
"mailServer,paymentAuthType,paymentAuthName,enableErrorHandling,cwDebug," &_
"dbType,ThisPage,ThisPageQS,ImageThumbFolder,ImageLargeFolder"
arVarList = Split(arVarList,",")
Dim i
For i = 0 to UBound(arVarList)
Execute("cwDebugOutput = cwDebugOutput & ""- " & arVarList(i) & ": "" & " & arVarList(i) & " & ""
""")
Next
cwDebugOutput = cwDebugOutput & "
"
'Output all VBScript collections
Dim collectionItem
Dim arCollections : arCollections = Array("Application.Contents","Session.Contents","Request.Form","Request.Querystring","Request.Cookies","Request.ServerVariables")
For i = 0 to UBound(arCollections)
cwDebugOutput = cwDebugOutput & ("
" & arCollections(i) & "
")
Execute("For Each collectionItem in " & arCollections(i) & ":cwDebugOutput = cwDebugOutput & ""- "" & collectionItem & "": "" & " & arCollections(i) & "(collectionItem) & ""
"":Next")
cwDebugOutput = cwDebugOutput & ("
")
Next
cwDebugOutput = cwDebugOutput & "
"
cwDebugOutput = cwDebugOutput & ""
End If
End Function 'cwDebugOutput
Function cwGetFullReturnURL(pagePath)
'---------------------------------------------------------------------
'Created: November 19, 2005
'Modified: November 19, 2005
'FUNCTION: cwGetFullReturnURL
'DESCRIPTION: Builds a full HTTP return URL based on the websiteURL
' variable declared in Application.asp and the pagePath passed to the
' function. If no pagePath is passed, then the SCRIPT_NAME for the
' current page will be used.
'ARGUMENTS
' pagePath: The page to build a full HTTP address to.
'RETURNS
'A string containing the full HTTP path of the return url page.
'EXAMPLES:
'Output all of the collected debug output.
' cwGetFullReturnURL(null)
' cwGetFullReturnURL(ThisPageQS)
'---------------------------------------------------------------------
If IsNull(pagePath) Then pagePath = Request.ServerVariables("SCRIPT_NAME")
'Get the location of the final / in the pagePath
Dim SlashPosition : SlashPosition = InStrRev(pagePath, "/")
If SlashPosition <> 0 Then
pagePath = Mid(pagePath, SlashPosition + 1)
End If
cwGetFullReturnURL = websiteURL & pagePath
End Function
%>
<%
'================================================================
'Application Info:
' Cartweaver© 2002 - 2005, All Rights Reserved.
'Developer Info:
' Application Dynamics Inc.
' 1560 NE 10th
' East Wenatchee, WA 98802
'Support Info: http://www.cartweaver.com/go/asphelp
'
'Cartweaver Version: 2.4 - Date: 11/27/2005
'================================================================
'Name: Cartweaver Cart Object
'Description: This is the heart of the Cartweaver application.
' When a customer adds, updates or deletes an item in their cart,
' this is the file that does the work. Cartweaver stores the
' actual cart data in tbl_cart in the database and maintains the
' Cart ID in a client cookie (Request.Cookies("CartID")). The
' cookie is set when the object is created if it doesn’t exist.
' The Cartweaver Object can be used on any page in your site.
' It is included in the CWIncDetails.asp and CWIncShowCart.asp
' files by default.
'See each individual property and method for more information on
' their syntax and usage.
'================================================================
'*Do Not Remove This Line* Prevents extraneous %@LANGUAGE="VBSCRIPT"% declaration from being added by Dreamweaver.
Class cwObjCartweaver
'Store internal result strings.
Dim cwResult
Dim cwStockAlert
Dim cwError
Dim cwCartCount
Dim cwi
Dim qtyRequested
Private Sub Class_Initialize()
'Create new cart if it doesn't exist.
If Request.QueryString("cart") <> "" Then
Response.Cookies("CartID") = Request.QueryString("cart")
Response.Cookies("CartID").Expires = Now() + 7
ElseIf Request.Cookies("CartID") = "" Then
Response.Cookies("CartID") = Session.SessionID
Response.Cookies("CartID").Expires = Now() + 7
End If
'Fill results from querystrings if they exist.
If Request.QueryString("result") <> "" Then cwResult = Request.QueryString("result")
If Request.QueryString("StockAlert") <> "" Then cwStockAlert = Request.QueryString("StockAlert")
End Sub
Private Sub Class_Terminate()
'Clean up recordsets involved with cwObjCartweaver.
'Always call Set cwObjCartweaver = Nothing when done.
End Sub
Public Property Get Count
'This property returns the number of items currently in the user’s cart.
'This property is read-only.
Count = getCount()
End Property
Public Property Get Result
'This property returns the number of items added to the cart with the last call of the Add or Update methods.
'This property is read-only.
Result = cwResult
End Property
Public Property Get CartError
'This property returns any errors generated by the cart actions.
'This property is read-only.
CartError = cwError
End Property
Public Property Get StockAlert
'This property returns True or False if a product is or is not out of stock.
'This property is read-only.
If cwStockAlert = "" Then cwStockAlert = False
StockAlert = cwStockAlert
End Property
Public Function Add(SKU,Qty,bolRedirect)
'Add one or more SKUs to the cart as defined by the SKU and Qty
' Arguments. To add multiple SKUs, pass a comma separated list
' of SKUs and quantities. The multiple SKU additions are used on
' CWIncDetails.asp when adding products from a crosstab table of
' SKUs, where multiple SKUs can be added at one time. This method
' has the following arguments:
' * SKU: The SKU argument passes either a specific SKU ID or a
' comma separated list of SKU IDs. The SKU ID passed is the
' SKU_ID field from tbl_skus. If a comma separated list of SKU
' IDs is passed, the Qty argument should contain a matching
' list of quantities.
' * Qty: The Qty argument passes either a single quantity or a
' comma separated list of quantities. If 0 is passed, the SKU is
' deleted from the cart. If a comma separated list of SKU IDs is
' passed, the Qty argument should contain a matching list of
' quantities.
' * bolRedirect: This value should be either True or False, whether
' to redirect based on user preferences. This value should be set
' to False while running through a list of SKUs.
Dim skuList : skuList = makeNumericArray(SKU)
Dim qtyList : qtyList = makeNumericArray(Qty)
'If we have an array of products, add each one.
If IsArray(skuList) Then
qtyRequested = 0
For cwi = 0 to UBound(skuList)
If cwi = UBound(skuList) Then 'If this is the last one, add, and redirect.
Add skuList(cwi), qtyList(cwi), True
Else 'We still have skus, so don't redirect quite yet.
Add skuList(cwi), qtyList(cwi), False
End If 'cwi = UBound(skuList)
Next 'cwi = 0 to UBound(skuList)
Exit Function
End If 'IsArray(skuList)
If NOT IsNumeric(SKU) Then cwError = "The SKU ID must be a numeric value." : Exit Function
If NOT IsNumeric(Qty) Then cwError = "Please enter a valid quantity." : Exit Function
If Qty = 0 AND cwResult = 0 AND cwStockAlert = False Then
cwError = "Please choose a valid quantity." : Exit Function
Else
cwError = ""
End if
Qty = Abs(Round(Qty))
qtyRequested = qtyRequested + Qty
'======Start all of the add work======
'Check for items already in the cart, and if it's there, just update it.
Dim rsCheckSku
Set rsCheckSku = cwOpenQuery("SELECT cart_Line_ID, cart_sku_qty FROM tbl_cart WHERE cart_custcart_ID ='" & Request.Cookies("CartID") & "' AND cart_sku_ID = " & SKU,datasource)
cwDebugger "rsCheckSku: " & rsCheckSku.Source
cwDebugger "rsCheckSku.EOF: " & rsCheckSku.EOF
'If we've got a match, do the update.
If NOT rsCheckSku.EOF Then
'Get number added
cwResult = cwResult + (CheckStockCount(SKU,rsCheckSku("cart_sku_qty") + Qty) - rsCheckSku("cart_sku_qty"))
cwDebugger "cwObjCartweaver, cwResult for sku " & SKU & ": " & cwResult
Call Update(rsCheckSku("cart_Line_ID"), CheckStockCount(SKU,rsCheckSku("cart_sku_qty") + Qty))
cwCloseRecordset(rsCheckSku)
If cwResult <> 0 AND CLng(cwResult) = CLng(qtyRequested) Then
cwStockAlert = False
Else 'QtyAdded = 0 OR QtyAdded <> qtyRequested
cwStockAlert = True
End If 'QtyAdded <> 0 AND QtyAdded = qtyRequested
Exit Function
End If 'NOT rsCheckSku.EOF
cwCloseRecordset(rsCheckSku)
'If it wasn't an update, then add it.
Qty = CheckStockCount(SKU,Qty)
cwDebugger "cwObjCartweaver, CheckStockCount for sku " & sku & ": " & Qty
If Qty <> 0 Then Call cwExecuteQuery("INSERT INTO tbl_cart (cart_custcart_ID, cart_sku_ID, cart_sku_qty, cart_dateadded) VALUES ('" & Request.Cookies("CartID") & "'," & SKU & "," & Qty & ", " & cwMakeSQLDate(Now(), True) & ");",datasource,Null)
cwResult = cwResult + Qty
If bolRedirect Then 'If it's time to redirect.
If cwResult <> 0 AND CLng(cwResult) = CLng(qtyRequested) Then
cwStockAlert = False
Else 'QtyAdded = 0 OR QtyAdded <> qtyRequested
cwStockAlert = True
End If 'QtyAdded <> 0 AND QtyAdded = qtyRequested
End If 'bolRedirect
End Function 'Add
Public Function Update(LineID,QtyNew)
'Update a specific item in the cart to a specific quantity as
' defined by the LineID and QtyNew arguments. Setting the quantity
' to 0 will delete an item from the cart. This method has the
' following arguments:
' * LineID: This argument is the cart_Line_ID from tbl_Cart that
' should be updated.
' * QtyNew: This argument is the new quantity for the specified
' LineID.
Dim lineList : lineList = makeNumericArray(LineID)
Dim qtyList : qtyList = makeNumericArray(QtyNew)
'If we have an array of products, add each one.
If IsArray(lineList) Then
For cwi = 0 to UBound(lineList)
If qtyList(cwi) <> 0 Then
UpdateLineItem lineList(cwi), CheckStockByLineID(lineList(cwi), qtyList(cwi))
Else
Delete lineList(cwi)
End If 'qtyList(cwi) <> 0
Next 'cwi = 0 to UBound(lineList)
Exit Function
Else
If lineList = -1 Then cwError = "The Line ID must be a numeric value." : Exit Function
If qtyList = -1 Then cwError = "The quantity must be a numeric value." : Exit Function
If QtyNew <> 0 Then
UpdateLineItem LineID, CheckStockByLineID(LineID, QtyNew)
Else
Delete LineID
End If 'QtyNew <> 0
End If 'IsArray(skuList)
End Function 'Update
Private Function UpdateLineItem(LineID, Qty)
Call cwExecuteQuery("UPDATE tbl_cart SET cart_sku_qty = " & Qty & " WHERE cart_line_id = " & LineID & ";",datasource,Null)
End Function
Public Function Delete(LineID)
'Delete an item from the cart as defined by the LineID
' argument. This method has one argument, LineID, which
' is the cart_Line_ID from tbl_Cart that should be deleted.
If LineID = "" Then LineID = 0
Call cwExecuteQuery("DELETE FROM tbl_cart WHERE cart_line_id IN (" & LineID & ");",datasource,Null)
End Function 'Delete
Public Function MultiOption(options,productID,qty)
'Add a SKU based on the SKU options as defined in the Options
' argument. The appropriate SKU is found for you based on the
' options passed to the object. The CWIncDetails.asp include
' uses this method when adding products with two options.
' This method has the following arguments:
' * Options: This argument should contain a comma separated
' list of option IDs for the product that should be added
' to the cart. This is used along with the Product ID to
' find the correct SKU to add to the cart.
' * ProductID: The numeric Product ID for the product that
' should be added to the cart. This is used along with the
' options list to find the correct SKU to add to the cart.
' * Qty: The quantity of items to add to the cart.
Dim arOptions
If NOT IsNumeric(options) Then
arOptions = makeNumericArray(options)
If NOT IsArray(arOptions) Then cwError = "The optionlist must be a numeric group of values" : Exit Function
Else
arOptions = Split(options,",")
End If
If NOT IsNumeric(qty) Then cwError = "The quantity must be a numeric group of values" : Exit Function
Dim numOptions : numOptions = UBound(arOptions) + 1
Dim optionList, i
For i = 0 to UBound(arOptions)
optionList = optionList & "," & arOptions(i)
Next
optionList = Mid(optionList,2)
'Get any found skus. Use optionList to filter the recordset
Dim rsSKU, query_rsSKU
query_rsSKU = "SELECT tbl_skus.SKU_ID " &_
"FROM tbl_skus " &_
"INNER JOIN tbl_skuoption_rel ON tbl_skus.SKU_ID = tbl_skuoption_rel.optn_rel_SKU_ID " &_
"WHERE tbl_skuoption_rel.optn_rel_Option_ID In (" & optionList & ") " &_
"GROUP BY tbl_skus.SKU_ID, tbl_skus.SKU_ProductID " &_
"HAVING tbl_skus.SKU_ProductID = " & productID & " AND Count(tbl_skuoption_rel.optn_rel_Option_ID) = " & numOptions & ";"
Set rsSKU = cwOpenQuery(query_rsSKU,datasource)
If NOT rsSKU.EOF Then
'Add the sku to be added to our cart to the end of our array
Call Add(rsSKU("SKU_ID"),qty,True)
Else
cwError = "No product matches the combination of options you have selected."
rsSKU.Close()
Set rsSKU = Nothing
Exit Function
End If
End Function 'MultiOption
Private Function CheckStockByLineID(LineID, QtyRequested)
If NOT Application("AllowBackOrders") Then
Dim rsStockSKU, newQty
Set rsStockSKU = cwOpenQuery("SELECT cart_sku_id FROM tbl_cart WHERE cart_line_ID = " & LineID, datasource)
newQty = CheckStockCount(rsStockSKU("cart_sku_id"), QtyRequested)
If cwStockAlert = False AND CLng(newQty) <> CLng(QtyRequested) Then
cwStockAlert = True
End If
cwDebugger "CheckStockByLineID: " & newQty & " : " & QtyRequested
CheckStockByLineID = newQty
Else
CheckStockByLineID = QtyRequested
End If
End Function
Public Function CheckStockCount(SKU,QtyRequested)
'This function is used to check if there is enough stock to
' fulfill a user’s quantity request. The function will
' return the total available stock for a product. If backorders
' are allowed, it will simply return the value based through
' the QtyRequested argument. This method has the following
' arguments:
' * SKU: The numeric SKU ID of the item to check against.
' * QtyRequested: The quantity requested by the user.
CheckStockCount = QtyRequested
If NOT CBool(Application("AllowBackOrders")) Then
'If Backorders are not allowed Check total quantity in the cart to be sure
'that the updated amount will not exceed the stock count.
'If it does, adjust quantity to Stock Count.
Dim rsStockCount
Set rsStockCount = cwOpenQuery("SELECT SKU_Stock FROM tbl_skus WHERE SKU_ID = " & SKU,datasource)
cwDebugger "CheckStockCount stock for sku " & sku & ": " & rsStockCount("sku_stock")
cwDebugger "CheckStockCount qty requested for sku " & sku & ": " & QtyRequested
'If the new quantity exceeds the stock quantity
If CLng(rsStockCount("sku_stock")) <= 0 Then
CheckStockCount = 0
Else
If CLng(QtyRequested) > CLng(rsStockCount("sku_stock")) Then
CheckStockCount = rsStockCount("sku_stock")
End If 'QtyRequested > rsStockCount
End If 'rsStockCount("sku_stock") <= 0
cwCloseRecordset(rsStockCount)
End If 'NOT Application("AllowBackOrders")
End Function 'CheckStockCount
Public Function ClearCart()
'This function clears the user’s cart of all contents, sets
' their cart ID to an empty string, and clears their
' Session("CheckingOut") variable. This function has no
' arguments.
Call cwExecuteQuery("DELETE FROM tbl_cart WHERE cart_custcart_ID = '" & Request.Cookies("CartID") & "';",datasource,Null)
'Clear all Cart Variables
Response.Cookies("CartID") = ""
Session("CheckingOut") = ""
End Function 'ClearCart
Private Function getCount()
'This function returns the number of items in the cart. There are no arguments for this method.
Dim rsCartCount
Set rsCartCount = cwOpenQuery("SELECT Sum(tbl_cart.cart_sku_qty) AS cartCount " &_
"FROM tbl_cart GROUP BY tbl_cart.cart_custcart_ID " &_
"HAVING tbl_cart.cart_custcart_ID = '" & Request.Cookies("CartID") & "';", datasource)
getCount = 0
If NOT rsCartCount.EOF Then getCount = rsCartCount("cartCount")
cwCloseRecordset(rsCartCount)
End Function 'getCount()
Private Function makeNumericArray(str)
'This function takes a comma separated list of numeric values
' and creates an array. If there is only one value passed,
' that single value is returned as a string. If there are any
' non-numeric values, they are converted to a 0. This is used
' to ensure that alpha characters are not passed to the Add
' and Update methods during multiple SKU additions. This
' function has one argument, str, which is a comma separated
' list of values to convert into an array.
Dim ar, i
ar = Split(str,",")
For i = 0 to UBound(ar)
'If the value isn't numeric, make it 0.
If NOT IsNumeric(ar(i)) Then ar(i) = 0
Next
If UBound(ar) = 0 Then
makeNumericArray = ar(0)
Else
makeNumericArray = ar
End If
End Function 'makeNumericArray
End Class 'cwObjCartweaver
%>
<%
'Start Cartweaver Cart
Set cwCart = New cwObjCartweaver
%>
<%
'============================================================================
'This is the presentation file for the Home Page. We have placed
'a few example searches to demonstrate how they will look on the page.
'============================================================================
%>