% ' ============================================================================= ' basket.asp ' Display page for Basket ' ' Commerce Server 2000 Solution Sites 1.0 ' ----------------------------------------------------------------------------- ' This file is part of Microsoft Commerce Server 2000 ' ' Copyright (C) 2000 Microsoft Corporation. All rights reserved. ' ' This source code is intended only as a supplement to Microsoft ' Commerce Server 2000 and/or on-line documentation. See these other ' materials for detailed information regarding Microsoft code samples. ' ' THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY ' KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE ' IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A ' PARTICULAR PURPOSE. ' ============================================================================= ' Prediction Constants -- These must match the PivotColumn for the view/table used in ' PredictorDataTables in the Data Warehouse Const PREDICTOR_PIVOT_COLUMN = "SKU" Const PREDICTOR_AGGREGATE_COLUMN = "QTY" Sub Main() Dim mscsOrderGrp Dim iErrorLevel, i, bBasketIsEmpty, bMustSaveBasket Dim iErrorCount Dim sOrderFormName Dim oOrderFormDisplayOrder Dim iCustomer_Type iCustomer_Type = 0 If m_UserType = AUTH_USER Then Dim rsUserDetails Set rsUserDetails = GetCurrentUserProfile() iCustomer_Type = rsUserDetails.Fields("GeneralInfo.Customer_Type") Set rsUserDetails = Nothing End If Call EnsureAccess() Call InitializeBasketPage(mscsOrderGrp, bBasketIsEmpty, bMustSaveBasket, oOrderFormDisplayOrder, iCustomer_Type) If Not bBasketIsEmpty Then ' Run basket pipeline to check for errors; set oOrderFormDisplayOrder Call CheckBasket(mscsOrderGrp, bBasketIsEmpty, iErrorCount, bMustSaveBasket, oOrderFormDisplayOrder) End If If Not bBasketIsEmpty Then ' Add discount footnote symbols to each lineitem Call AddDiscountMessages(mscsOrderGrp) End If If bMustSaveBasket Then ' Save the basket (changes may have occurred when running the pipeline) Call mscsOrderGrp.SaveAsBasket() End If Call RenderBasketPage(mscsOrderGrp, oOrderFormDisplayOrder, bBasketIsEmpty, iErrorCount, iCustomer_Type) End Sub ' ----------------------------------------------------------------------------- ' InitializeBasketPage ' ' Description: ' Helper sub to initialize variables; called by Main ' ' Parameters: ' ' Returns: ' ' Notes : ' none ' ----------------------------------------------------------------------------- Sub InitializeBasketPage(ByRef objOrderGroup, ByRef bBasketIsEmpty, ByRef bMustSaveBasket, ByRef oOrderFormDisplayOrder, ByVal iCustomer_Type) bBasketIsEmpty = True Set objOrderGroup = LoadBasket(m_UserID) If objOrderGroup.Value(TOTAL_LINEITEMS) > 0 Then bBasketIsEmpty = False End If bMustSaveBasket = False 'Assume that view basket operations don't require a SaveBasket. 'This may be an invalid assumption for certain pipelines. 'If this applies to your pcf, initialize this variable 'to "Not bBasketEmpty" Set oOrderFormDisplayOrder = Nothing End Sub ' ----------------------------------------------------------------------------- ' CheckBasket ' ' Description: ' Get the updated basket information ' ' Parameters: ' ' Returns: ' ' Notes : ' none ' ----------------------------------------------------------------------------- Sub CheckBasket(mscsOrderGrp, ByRef bBasketIsEmpty, ByRef iErrorCount, ByRef bMustSaveBasket, ByRef oOrderFormDisplayOrder) Dim iErrorLevel, mscsOrderForm ' Remove empty orderforms to prevent basket pipeline from raising pur_noitems purchase error. Call RemoveEmptyOrderForms(mscsOrderGrp) Dim iCustomer_Type iCustomer_Type = 0 If m_UserType = AUTH_USER Then Dim rsUserDetails Set rsUserDetails = GetCurrentUserProfile() iCustomer_Type = rsUserDetails.Fields("GeneralInfo.Customer_Type") Set rsUserDetails = Nothing End If Set mscsOrderForm = mscsOrderGrp.Value("Orderforms")("Default") mscsOrderForm("Customer_Type") = iCustomer_Type mscsOrderForm("strConnStr") = Application("DBConnect") 'Response.Write icustomer_type 'Response.end ' First, run the pipeline, to get the latest information. iErrorLevel = RunMtsPipeline(MSCSPipelines.Basket, GetPipelineLogFile("Basket"), mscsOrderGrp) '*********************************************** '* Freebie Promo Code - '* see include file lc_freebie_promo.asp '*********************************************** ' Run the free item promo check If RunFreebiePromoCheck(mscsOrderGrp) = TRUE Then iErrorLevel = RunMtsPipeline(MSCSPipelines.Basket, GetPipelineLogFile("Basket"), mscsOrderGrp) End If ' Sort the orderforms Set oOrderFormDisplayOrder = SortDictionaryKeys(mscsOrderGrp.Value(ORDERFORMS)) If iErrorLevel > 1 Then ' Handle basket errors only. Components in basket pipeline must not raise purchase errors. ' Calling RemoveEmptyOrderForms() before executing the basket pipeline eliminates the ' possibility of pur_noitems purchase error being raised. iErrorCount = GetErrorCount(mscsOrderGrp, BASKET_ERRORS) If iErrorCount > 0 Then ' If there is a basket error, we should save the pipeline, so that ' the same error doesn't keep occuring. An alternative implementation would ' be to prompt for user acknowledgement upon basket error bMustSaveBasket = True ElseIf GetErrorCount(mscsOrderGrp, PURCHASE_ERRORS) > 0 Then Err.Raise vbObjectError + 2111, , mscsMessageManager.GetMessage("L_Bad_Pipeline_Warning_ErrorMessage", sLanguage) Else Err.Raise vbObjectError + 2110, , mscsMessageManager.GetMessage("L_Unspecified_Pipeline_Warning_ErrorMessage", sLanguage) End If ' Pipeline run may have removed the last item from the basket. Cannot learn this ' from mscsOrderGrp.Value(TOTAL_LINEITEMS) since pipeline run does not update it. If GetLineItemsCount(mscsOrderGrp) = 0 Then bBasketIsEmpty = True End If End If End Sub ' ----------------------------------------------------------------------------- ' CreatePOIndexes ' ' Description: ' ' Parameters: ' ' Returns: ' ' Notes : ' none ' ----------------------------------------------------------------------------- Sub CreatePOIndexes(mscsOrderGrp) Dim i, sOrderFormName, oOrderForm, oItem For Each sOrderFormName In mscsOrderGrp.value(ORDERFORMS) Set oOrderForm = mscsOrderGrp.value(ORDERFORMS).Value(sOrderFormName) i=0 For Each oItem In oOrderForm.Items oItem.value("_poname") = sOrderFormName oItem.value("_poindex") = i i = i + 1 Next Next End Sub ' ----------------------------------------------------------------------------- ' Rendering functions ' ----------------------------------------------------------------------------- ' ----------------------------------------------------------------------------- ' RenderBasketPage ' ' Description: ' Render the Basket Page, including basket contents, discounts, errors ' ' Parameters: ' ' Returns: ' ' Notes : ' none ' ----------------------------------------------------------------------------- Sub RenderBasketPage(mscsOrderGrp, oOrderFormDisplayOrder, bBasketIsEmpty, iErrorCount, iCustomer_type) Dim htmTitle, htmContent, urlLink Dim BasketAffinity, ProductAffinity, nDiscountsToShow sPageTitle = mscsMessageManager.GetMessage("L_Basket_HTMLTitle", sLanguage) 'sPageTitle ="Basket" '*********************** '* '*********************** iPageNumber = 1 sCatalogName = "Products" Set oCatalog = MSCSCatalogManager.GetCatalog(sCatalogName) If oCatalog Is Nothing Then Response.Redirect(GenerateURL(MSCSSitePages.BadCatalogItem, Array(), Array())) End If sBlankCategoryName = "Categories" Set oCategory = mscsGetCategoryObject(oCatalog, sBlankCategoryName) Set rsProducts = mscsGetProductList(oCatalog, oCategory, iPageNumber, nRecordsTotal, nOutPagesTotal) htmCategoryContent =htmCategoryHTML(oCatalog, sCatalogName, sBlankCategoryName, oCategory, rsProducts, iPageNumber, nOutPagesTotal, sCacheKey) Set rsProducts = Nothing Set oCategory = Nothing 'htmContent = sPageTitle 'MV Response.Write "
"
'*******************************************
'* Code for background tables
'*******************************************
htmFullPageContent = htmFullPageContent & "
" End If Exit Function End If ' Construct the input case from the items in the basket. ' The constructed property name in the input dictionary ' is of the form: [Catalog Name].[Product ID]. This ' must correspond to the format used for "SKU" in the ' Trans_Predictor view in the data warehouse. Thes means ' that we treat all variants of a product equally ' for the purposes of prediction. Set dCase = GetDictionary() Set slToPredict = GetSimpleList() ' Add list of properties to predict. For product recommendations, ' we give the name of the PivotColumn defined in PredictorDataTables. slToPredict.Add PREDICTOR_PIVOT_COLUMN For Each sOrderFormName in oOrderFormDisplayOrder Set oOrderForm = mscsOrderGrp.value.OrderForms.Value(sOrderFormName) For Each dItem in oOrderForm.Items strPropName = PREDICTOR_AGGREGATE_COLUMN & "([" & dItem.product_catalog & "].[" & dItem.product_id & "])" lQuantity = CLng(dItem.quantity) dCase(strPropName) = lQuantity Next Next ' Call the predictor. lMaxPredictions = 5 'Display no more than this many predictions. oPredictor.Predict dCase, slToPredict, arPredictedProps, arPredictedVals, lMaxPredictions If IsArray(arPredictedProps) Then htmContent = "" & mscsMessageManager.GetMessage("L_RecommendationsCaption_HTMLText", sLanguage) & " " For i = 0 To UBound(arPredictedProps) strHREF = PredictedPropToHREF(arPredictedProps(i)) htmContent = htmContent & strHREF & " " Next arPredictedProps = Empty arPredictedVals = Empty End If htmRenderPredictions = htmContent End Function ' ----------------------------------------------------------------------------- ' PredictedPropToHREF ' ' Description: ' Construct a hyperlink into the catalog from the prediction information. ' ' Parameters: ' ' Returns: ' ' Notes : ' none ' ----------------------------------------------------------------------------- Function PredictedPropToHREF(strProp) Dim regEx1 Dim arProps Dim strCatalogName Dim strProductID Dim strProps Dim strHREF Set regEx1 = New RegExp ' The prediction property will return in the form: ' QTY([Catalog Name].[Product ID]) regEx1.Pattern = PREDICTOR_AGGREGATE_COLUMN & "\(\[(.+)\]\.\[(.+)\]\)" strProps = regEx1.Replace(strProp, "$1;$2") arProps = Split(strProps, ";") strCatalogName = arProps(0) strProductID = arProps(1) PredictedPropToHREF = "" & strProductID & "" End Function ' ----------------------------------------------------------------------------- ' htmCategoryHTML ' ' Description: ' Generate HTML display of the given data ' ' Parameters: ' ' Returns: ' ' Notes : ' none ' ----------------------------------------------------------------------------- Function htmCategoryHTML(oCatalog, sCatalogName, sCategoryName, oCategory, rsProducts, iPageNumber, nOutPagesTotal, sCacheKey) Dim htmPageContent Dim htmTitle ' Render the page title If IsNull(sCategoryName) Then htmTitle = RenderText_Title(sCatalogName, MSCSSiteStyle.Title) Else htmTitle = RenderText_Title(sCategoryName, MSCSSiteStyle.Title) End If htmPageContent = htmTitle & CRLF & htmRenderCategoryPage(oCatalog, sCatalogName, sCategoryName, oCategory, rsProducts, iPageNumber, nOutPagesTotal) Call CacheFragment("ProductListCache", sCacheKey, htmPageContent) htmCategoryHTML = htmPageContent End Function ' ----------------------------------------------------------------------------- ' htmRenderBasketWarnings ' ' Description: ' ' Parameters: ' ' Returns: ' ' Notes : ' none ' ----------------------------------------------------------------------------- Function htmRenderInventoryError(mscsOrderGrp) 'htmContent = htmContent & RenderText("this is a test", MSCSSiteStyle.Warning) & BR 'MV htmRenderInventoryError = RenderText(mscsordergrp("InventoryQtyError"), MSCSSiteStyle.Warning) mscsordergrp("InventoryQtyError") = "" End Function %> | |||||||||||||||||||||||||||||||