Previous in Contents Next in Contents

Predictor Example: Microsoft Press Basket.asp

The Basket.asp page displays items that the customer has ordered, or placed in the shopping basket. In this example, from the Microsoft Press® site, the Basket.asp page includes Intelligent Cross-Sell, by suggesting other items that the customer might be interested in based on the contents of the basket and on the site purchase history.

Before the page can call the GetPredictions method, it must create a list of purchased items to pass to this method. This list already exists in the OrderForm object, assuming that the customer has already placed at least one item in the basket. The list of items is a property of the OrderForm object and is named Items. (Refer to the figure in OrderForm Object Overview.)

The following code is invoked immediately after the OrderForm object is created. The code creates a variable called orderitems, which references the item list if an order form exists for this customer:

set orderitems = mscsOrderForm.Items

This list of items is later passed as an argument to GetPredictions.

The following code calls the GetPredictions method, which returns the resulting suggested items in a SimpleList object called products. This list is then enumerated, and for each item, the SKU value is passed in a query to return the name of a suggested item (the title of a book). The SKU and book title are also used to generate a URL for the product page of the suggested book to create a link, which the customer can click for more information:

<% REM Display a list of predictive data 
   predictor = NULL
   on error resume next
set predictor = Application("MSCSPredictor")
   on error goto 0

if Not IsNull(predictor) and Not IsEmpty(predictor) then
   set predictions = predictor.GetPredictions(orderItems, 6, 0.3, 2)
        if predictions.Count > 0 then
header = 0
for i = 0 to predictions.Count - 1
   cmdTemp.commandText = "select title from mspress30_product where sku = '" & predictions(i).sku & "'"
   set product = Server.CreateObject("ADODB.RecordSet")
   product.Open cmdTemp, , adOpenKeyset, adLockReadOnly
   if predictions.Count > 0 then
      if header = 0 then
         Response.Write("Other people who have bought the books you are interested in have also purchased the following titles:")
         Response.Write("<P>")
         header = 1
      end if
   %>
      <A HREF="<% = mscsPage.URL("product.asp", "sku", predictions(i).sku) %>"><% = product("title") %></A>
      <br>
   <%      end if
next
        end if
end if
   %>
<% end if %>

© 1997-2000 Microsoft Corporation. All rights reserved.