<% 'On Error Resume Next Class O_cart Public oBase Public oConn Public iID Private aProducts() Sub Class_Initialize() Set oBase = Base 'Catalogue Config Populate End Sub Function Connect(objConn,intID) Set oConn = objConn iID = intID End Function Function AddToCart(nID) Dim sReturn Dim intQty sReturn = "" If Request.QueryString("qty") <> "" Then intQty = Request.QueryString("qty") Else intQty = 1 End If nID = Request.QueryString("item") If IsObject(Session("IIS_CART")) Then Set oCart = Session("IIS_CART") If oCart.Exists(nID) Then oCart(nID) = intQty Else oCart(nID) = intQty End If Save(oCart) Set oCart = Nothing Else Set oCart = Server.CreateObject("Scripting.Dictionary") oCart.Add nID, intQty Save(oCart) Set oCart = Nothing End If End Function Function Change_Quantity(nID) Dim intQty intQty = cInt(Request.QueryString("qty")) If intQty = "" Then intQty = 1 End If nID = Request.QueryString("item") If IsObject(Session("IIS_CART")) Then Set oCart = Session("IIS_CART") If oCart.Exists(nID) Then If intQty > 0 Then oCart(nID) = intQty Else oCart.Remove(nID) End If End If Save(oCart) Set oCart = Nothing End If End Function Sub Save(oCart) Set Session("IIS_CART") = oCart End Sub Function Remove(nID) nID = Request.QueryString("item") If IsObject(Session("IIS_CART")) Then Set oCart = Session("IIS_CART") If oCart.Exists(nID) Then oCart.Remove(nID) End If Save(oCart) Set oCart = Nothing End If Response.Redirect(Request.ServerVariables("HTTP_REFERER")) End Function Function Clear_Cart(nID) If IsObject(Session("IIS_CART")) Then Session.Contents.Remove("IIS_CART") End If End Function Function CartCount(nID) Dim intCount intCount = 0 If IsObject(Session("IIS_CART")) Then intCount = Session("IIS_CART").Count End If Response.Write(intCount) End Function Function View_Cart(nID) Response.Write(ShoppingCartView("view-cart")) End Function Function CartStatus(nID) strReturn = "" If IsObject(Session("IIS_CART")) Then If Session("IIS_CART").Count = 1 Then strReturn = "You have 1 item in your shopping cart." ElseIf Session("IIS_CART").Count > 1 Then strReturn = "You have "&Session("IIS_CART").Count&" items in your shopping cart." ElseIf Session("IIS_CART").Count = 0 Then strReturn = "You have 0 items in your shopping cart." End If Else strReturn = "You have 0 items in your shopping cart." End If Response.Write(strReturn) End Function Function ShoppingCartView(sView) Dim oCart Dim i Dim iLineTotal Dim iSubTotal Dim iTotal Dim iVAT Dim iDelivery iTotal = 0 iSubTotal = 0 sFile = oBase.LoadView("cart",sView,1) aParts = DoSplit(sFile) sHeader = aParts(0) sFooter = aParts(2) If IsObject(Request.Form("billing_name")) Then sHeader = oBase.InsertValue(sHeader,"BILLING_NAME",Request.Form("billing_name")) sHeader = oBase.InsertValue(sHeader,"BILLING_ADDRESS",Replace(Request.Form("billing_address"),VbCrLf,"
")) sHeader = oBase.InsertValue(sHeader,"BILLING_EMAIL",Request.Form("billing_email")) sHeader = oBase.InsertValue(sHeader,"DELIVERY_NAME",Request.Form("delivery_name")) sHeader = oBase.InsertValue(sHeader,"DELIVERY_ADDRESS",Replace(Request.Form("delivery_address"),VbCrLf,"
")) sHeader = oBase.InsertValue(sHeader,"DELIVERY_ADDRESS_INPUT",Request.Form("delivery_address")) End If If IsObject(Session("IIS_CART")) Then Set oCart = Session("IIS_CART") Call GetProductInfo For Each Item in aProducts 'Response.Write("#" & Item & "#
") Next sFooter = oBase.InsertValue(sFooter,"NOTHING",False) sFooter = oBase.InsertValue(sFooter,"NOT_NOTHING",True) iLineTotal = 0 For i = 0 to uBound(aProducts,2) - 1 sRepeat = sRepeat & aParts(1) sRepeat = oBase.InsertValue(sRepeat,"ID",aProducts(8,i)) sRepeat = oBase.InsertValue(sRepeat,"PRODUCT_PAGE",sProductPage & aProducts(0,i)) sImages = GetFirstImage(aProducts(4,i)) If sImages <> "" Then aImages = Split(sImages,"|||") End If sRepeat = oBase.InsertValue(sRepeat,"IMAGE",aImages(1)) sRepeat = oBase.InsertValue(sRepeat,"NAME",aProducts(1,i)) sRepeat = oBase.InsertValue(sRepeat,"CODE",aProducts(2,i)) sRepeat = oBase.InsertValue(sRepeat,"HREF_REMOVE",URL2("cart","remove",0,"window=1&item=" & aProducts(8,i))) intPrice = 0 If aProducts(3,i) <> 0 Then intPrice = aProducts(3,i) Else intPrice = aProducts(6,i) End If If intPrice <> 0 Then intPrice = FormatNumber(intPrice,2) End If sRepeat = oBase.InsertValue(sRepeat,"PRICE",intPrice) For Each Item in oCart 'response.Write(Item & "
") Next sRepeat = oBase.InsertValue(sRepeat,"QUANTITY",aProducts(7,i)) iLineTotal = FormatNumber(intPrice * aProducts(7,i),2) sRepeat = oBase.InsertValue(sRepeat,"LINE_TOTAL",iLineTotal) iSubTotal = iSubTotal + iLineTotal iDelivery = iDelivery + 0 Next 'iVAT = (iSubTotal * 0.14) iVat = 0 iTotal = iSubTotal + iVAT + iDelivery sFooter = oBase.InsertValue(sFooter,"SUB_TOTAL",FormatNumber(iSubTotal,2)) sFooter = oBase.InsertValue(sFooter,"VAT",FormatNumber(iVAT,2)) sFooter = oBase.InsertValue(sFooter,"DELIVERY",FormatNumber(iDelivery,2)) sFooter = oBase.InsertValue(sFooter,"TOTAL",FormatNumber(iTotal,2)) sFooter = oBase.InsertValue(sFooter,"HREF_CHECKOUT",URL("cart","checkout",0)) sFooter = oBase.InsertValue(sFooter,"FORM_DATA",base64_encode(Request.Form)) Set oCart = Nothing Else sFooter = oBase.InsertValue(sFooter,"NOTHING",True) sFooter = oBase.InsertValue(sFooter,"NOT_NOTHING",False) End If ShoppingCartView = sHeader & sRepeat & sFooter End Function Function CartWidgetSmall intCounter = 0 sFile = oBase.LoadView("cart","widget",0) If IsObject(Session("iis_cart")) Then Set oCart = Session("iis_cart") intCounter = oCart.Count Set oCart = Nothing End If sFile = oBase.InsertValue(sFile,"COUNT",intCounter) Response.Write(sFile) End Function Function GetFirstImage(intID) Dim sQ Dim sReturn sQ = oDB.ExecuteQuery(oConn,"SELECT TOP 1 id, file_name FROM files WHERE file_folder = '" & intID & "'") If IsArray(sQ) Then strSrc = C_UPLOADS & "/" & intID & "/" & sQ(1,0) strThumb = C_UPLOADS & "/" & intID & "/thumbs/" & sQ(1,0) End If sReturn = strSrc & "|||" & strThumb GetFirstImage = sReturn End Function Function GetProductInfo Dim oCart Dim oTempConn Dim Item Dim sID Dim iCount iCount = 0 If IsObject(Session("IIS_CART")) Then Set oCart = Session("IIS_CART") 'Response.Write(oCart.Count) Redim aProducts(9,oCart.Count) For Each Item in oCart If Item <> "" Then aNames = Split(Item,"_") If uBound(aNames) > 1 Then intCategory = aNames(0) intProduct = aNames(1) intID = aNames(2) strPrice = GetVariantOption(intID,intProduct,"price") strSpecial = GetVariantOption(intID,intProduct,"special_price") aProducts(0,iCount) = intProduct aProducts(1,iCount) = oDB.GetValue(oConn,"productName","catalogue_products","WHERE id = " & intProduct) aProducts(2,iCount) = GetVariantValue(intID,intProduct) aProducts(3,iCount) = strPrice aProducts(4,iCount) = oDB.GetValue(oConn,"files_id","catalogue_products","WHERE id = " & intProduct) aProducts(5,iCount) = intCategory aProducts(6,iCount) = strSpecial aProducts(7,iCount) = oCart(Item) aProducts(8,iCount) = Item iCount = iCount + 1 End If End If Next Set oCart = Nothing End If End Function Function GetVariantOption(intCounter,intProduct,strProperty) Dim sValue sValue = "" sVariants = oDB.GetValue(oConn,"variationOptions","catalogue_products","WHERE id = " & intProduct) If sVariants <> "" Then Set oVariant = JSON.parse(sVariants) For Each Item in oVariant.options.get(0).keys() If Trim(Item) = Trim("var_options_"&intCounter) Then Set oItem = oVariant.options.get(0).get(Item) intCount = intCount + 1 sValue = Eval("oItem."&strProperty&"_" & intCounter) Set oItem = Nothing End If Next Set oVariant = Nothing End If GetVariantOption = sValue End Function Function GetVariantValue(intCounter,intProduct) Dim sQ Dim i strReturn = "" sVariants = oDB.GetValue(oConn,"productVariants","catalogue_products","WHERE id = " & intProduct) intCol = 0 If sVariants <> "" Then Set oVariant = JSON.parse(sVariants) Set oItem = oVariant.variants.get(0).get(intCounter) For Each Col in oItem.Keys() If intCol = 0 Then strReturn = Eval("oItem."&Col&"") intCol = intCol + 1 End IF Next Set oItem = Nothing Set oVariant = Nothing End If GetVariantValue = strReturn End Function Function Checkout(nID) Dim i If Profiles.Authorize(True) Then sFile = oBase.LoadView("cart","checkout",0) sQ = oDB.ExecuteQuery(oConn,"SELECT id, entity_name, entity_surname, email_address, address FROM profiles WHERE id = " & Session("logged_in_id")) If IsArray(sQ) Then sFile = oBase.InsertValue(sFile,"BILLING_NAME",sQ(1,0) & " " & sQ(2,0)) sFile = oBase.InsertValue(sFile,"BILLING_ADDRESS",Replace(sQ(4,0),VbCrLf,"
")) sFile = oBase.InsertValue(sFile,"BILLING_EMAIL",sQ(3,i)) sFile = oBase.InsertValue(sFile,"DELIVERY_NAME",sQ(1,0) & " " & sQ(2,0)) sFile = oBase.InsertValue(sFile,"DELIVERY_ADDRESS",sQ(4,0)) sFile = oBase.InsertValue(sFile,"HREF_ACTION",URL("cart","confirm_checkout",0)) End If Response.Write(sFile) Else sFile = oBase.LoadView("cart","login",0) Response.Write(sFile) End If End Function Function Confirm_Checkout(nID) Call Profiles.Authorize(False) Response.Write(ShoppingCartView("confirm-checkout")) End Function Function GetItemProperty(intID,strProperty) GetItemProperty = oDB.GetValue(oConn,strProperty,sProductTable,"WHERE id = " & intID) End Function Function GetCategoryProperty(intID, strProperty) GetCategoryProperty = oDB.GetValue(oConn,strProperty,"catalogue_categories","WHERE id = " & intID) End Function Function Confirm_Order(nID) Call GetProductInfo Set oOrder = Server.CreateObject("Scripting.Dictionary") oOrder.Add "profile_id", Session("logged_in_id") oOrder.Add "delivery_name", Request.Form("delivery_name") oOrder.Add "delivery_address", Request.Form("delivery_address") oOrder.Add "order_shipping", Request.Form("order_shipping") oOrder.Add "order_vat", Request.Form("order_vat") oOrder.Add "order_date", Date() intOrderID = oDB.ExecuteInsert(oConn,"catalogue_orders",oOrder) Set oOrder = Nothing If IsObject(Session("IIS_CART")) Then Set oCart = Session("IIS_CART") Else Set oCart = Server.CreateObject("Scripting.Dictionary") End If intItemCount = 0 For Each Item in oCart intPrice = aProducts(3,intItemCount) intLineTotal = intPrice * aProducts(7,intItemCount) oDB.ExecuteNonQuery oConn,"INSERT INTO catalogue_order_products (order_id, product_id, quantity, unit_price) VALUES ("&intOrderID&","&aProducts(0,intItemCount)&","&aProducts(7,intItemCount)&","&intPrice&")" intItemCount = intItemCount + 1 Next Set oCart = Nothing sContent = oBase.LoadView("cart","thanks",0) sEmail = oBase.LoadView("cart","email-confirmation",0) strDeliveryAddress = Request.Form("delivery_address") strDeliveryName = Request.Form("delivery_name") oBase.SendEmail Array(C_COMPANY_NAME,C_COMPANY_EMAIL),Array(Profiles.ProfileProperty(Session("logged_in_id"),"entity_name"),Profiles.ProfileProperty(Session("logged_in_id"),"email_address")),"Order Confirmation",sEmail oBase.SendEmail Array(C_COMPANY_NAME,C_COMPANY_EMAIL),Array(Profiles.ProfileProperty(Session("logged_in_id"),"entity_name"),Profiles.ProfileProperty(Session("logged_in_id"),"email_address")),"Your "&C_COMPANY_NAME&" Order",SendOrderEmail(intOrderID, strDeliveryAddress, strDeliveryName) oBase.SendEmail Array(C_COMPANY_NAME,C_COMPANY_EMAIL),Array(C_COMPANY_NAME,C_COMPANY_EMAIL),"New Website Order",SendOrderEmail(intOrderID, strDeliveryAddress,strDeliveryName) Call Clear_Cart(0) Response.Write(intOrderID) End Function Function SendOrderEmail(intOrderID, strDeliveryAddress, strDeliveryName) Call GetProductInfo Call Profiles.Authorize(False) sFile = oBase.LoadView("cart","email-cart",1) aParts = DoSplit(sFile) sHeader = aParts(0) sFooter = aParts(2) If IsObject(Session("IIS_CART")) Then Set oCart = Session("IIS_CART") Else Set oCart = Server.CreateObject("Scripting.Dictionary") End If If oCart.Count > 0 Then sHeader = oBase.InsertValue(sHeader,"NAME",Profiles.ProfileProperty(Session("logged_in_id"),"entity_name") & " " & Profiles.ProfileProperty(Session("logged_in_id"),"entity_surname")) sHeader = oBase.InsertValue(sHeader,"BILLING_ADDRESS",HTMLDecode(Replace(Profiles.ProfileProperty(Session("logged_in_id"),"address"),VbCrLf,"
"))) sHeader = oBase.InsertValue(sHeader,"DELIVERY_ADDRESS",Replace(strDeliveryAddress,VbCrLf,"
")) sHeader = oBase.InsertValue(sHeader,"DELIVERY_NAME",strDeliveryName) sHeader = oBase.InsertValue(sHeader,"ORDER_ID",intOrderID) intSubTotal = 0 intItemCount = 0 For Each Item in oCart sRepeat = sRepeat & aParts(1) sRepeat = oBase.InsertValue(sRepeat,"TITLE",aProducts(1,intItemCount)) sRepeat = oBase.InsertValue(sRepeat,"CODE",aProducts(2,intItemCount)) Response.Write(aProducts(5,intItemCount)) sRepeat = oBase.InsertValue(sRepeat,"CATEGORY",GetCategoryProperty(aProducts(5,intItemCount),"title")) sRepeat = oBase.InsertValue(sRepeat,"QTY",aProducts(7,intItemCount)) sRepeat = oBase.InsertValue(sRepeat,"ID",aProducts(0,intItemCount)) intPrice = aProducts(3,intItemCount) If intPrice <> 0 Then intLineTotal = intPrice * aProducts(7,intItemCount) Else intLineTotal = 0 End If intSubTotal = intSubTotal + intLineTotal sRepeat = oBase.InsertValue(sRepeat,"UNIT_PRICE","R " & FormatNumber(intPrice,2)) sRepeat = oBase.InsertValue(sRepeat,"LINE_TOTAL","R " & FormatNumber(intLineTotal,2)) intItemCount = intItemCount + 1 Next sFooter = oBase.InsertValue(sFooter,"SUB_TOTAL","R " & FormatNumber(intSubTotal,2)) End If Set oCart = Nothing SendOrderEmail = sHeader & sRepeat & sFooter End Function Function Paygate_Form(nID) intSubTotal = 0 intRef = nID sFile = oBase.LoadView("cart","paygate",0) 'Get order total sQ = oDB.ExecuteQuery(oConn,"SELECT SUM(unit_price * quantity) AS OrderTotal FROM catalogue_order_products WHERE order_id = " & nID) If IsArray(sQ) Then intSubTotal = sQ(0,0) End If 'Get customer e-mail sQ = oDB.ExecuteQuery(oConn,"SELECT email_address FROM profiles INNER JOIN catalogue_orders ON catalogue_orders.profile_id = profiles.id WHERE catalogue_orders.id = " & nID) If IsArray(sQ) Then strEmail = sQ(0,0) End If 'Get order totals sQ = oDB.ExecuteQuery(oConn,"SELECT SUM(order_shipping + order_vat) AS OrderTotals FROM catalogue_orders WHERE id = " & nID) If IsArray(sQ) Then intSubTotal = intSubTotal + sQ(0,0) End If intSubTotal = intSubTotal * 100 'Convert to cents for Paygate intPaygateID = C_PAYGATE_ID strSecret = C_PAYGATE_SECRET strReturnURL = C_SITE_ROOT & "/cart.asp?controller=cart&view=paygate_confirmation" strDate = Now() 'Calculate Checksum strMD = md5(intPaygateID & "|"&intRef&"|"&intSubTotal&"|ZAR|"&strReturnURL&"|"&strDate&"|"&strEmail&"|" & strSecret) sFile = oBase.InsertValue(sFile,"PAYGATE_ID",intPaygateID) sFile = oBase.InsertValue(sFile,"REFERENCE",intRef) sFile = oBase.InsertValue(sFile,"TOTAL",intSubTotal) sFile = oBase.InsertValue(sFile,"RETURN_URL",strReturnURL) sFile = oBase.InsertValue(sFile,"DATE",strDate) sFile = oBase.InsertValue(sFile,"EMAIL",strEmail) sFile = oBase.InsertValue(sFile,"CHECKSUM",strMD) Response.Write(sFile) End Function Function Paygate_Confirmation(nID) sFile = oBase.LoadView("cart","paygate-return",0) strMsg = "" If Request.Form("TRANSACTION_STATUS") = 1 Then sFile = oBase.InsertValue(sFile,"SUCCESSFUL",True) sFile = oBase.InsertValue(sFile,"ERROR",False) oDB.ExecuteNonQuery oConn, "UPDATE catalogue_orders SET order_paid = true WHERE id = "&Request.Form("REFERENCE") Else Select Case Request.Form("RESULT_CODE") Case 900001 strMsg = "Call for Approval" Case 900002 strMsg = "Card Expired" Case 900003 strMsg = "Insufficient Funds" Case 900004 strMsg = "Invalid Card Number" Case 900005 strMsg = "Bank Interface Timeout Indicates a communications failure between the banks systems." Case 900006 strMsg = "Invalid Card" Case 900007 strMsg = "Declined" Case 900009 strMsg = "Lost Card" Case 900010 strMsg = "Invalid Card Length" Case 900011 strMsg = "Suspected Fraud" Case 900012 strMsg = "Card Reported As Stolen" Case 900013 strMsg = "Restricted Card" Case 900014 strMsg = "Excessive Card Usage" Case 900015 strMsg = "Card Blacklisted" Case 900207 strMsg = "Declined; authentication failed Indicates the cardholder did not enter their MasterCard SecureCode / Verified by Visa password correctly." Case 990020 strMsg = "Auth Declined" Case 991001 strMsg = "Invalid expiry date" Case 900205 strMsg = "Unexpected authentication result (phase 1)" Case 900206 strMsg = "Unexpected authentication result (phase 1)" Case 990001 strMsg = "Could not insert into Database" Case 990022 strMsg = "Bank not available" Case 990053 strMsg = "Error processing transaction" Case 900209 strMsg = "Transaction verification failed (phase 2)" Case 900210 strMsg = "Authentication complete; transaction must be restarted" Case 990024 strMsg = "Duplicate Transaction Detected. Please check before submitting" Case 990028 strMsg = "Transaction cancelled" Case Else strMsg = "Your transaction was not successful due to technical errors. Please try again later." End Select oDB.ExecuteNonQuery oConn, "UPDATE catalogue_orders SET order_declined = '"&strMsg&"' WHERE id = "&Request.Form("REFERENCE") sFile = oBase.InsertValue(sFile,"SUCCESSFUL",False) sFile = oBase.InsertValue(sFile,"ERROR",True) sFile = oBase.InsertValue(sFile,"REASON",strMsg) sFile = oBase.InsertValue(sFile,"HREF_RETRY","cart.asp?controller=cart&view=paygate_form&id="&Request.Form("REFERENCE")) End If Response.Write(sFile) End Function End Class If Err.Number <> 0 Then 'Response.Write("Error") End If %>