Figure 2   Creating a Predictions List

<%
•••
if predictions.Count > 0 then
            
    header = 0

    for i = 0 to predictions.Count - 1
        cmdTemp.commandText = "select name from sitename_product " _
            & "where sku = '" & Replace(predictions(i).sku," _
            & "'", "''") & "'"
        set rsProduct = Server.CreateObject("ADODB.RecordSet")
        rsProduct.Open cmdTemp, , adOpenKeyset, adLockReadOnly
        if rsProduct.RecordCount > 0 then
            if header = 0 then
                Response.Write("Other people " _ 
                & " who have bought this product " _
                & " have also purchased the following titles:")
                Response.Write("<P>")
                header = 1
                    end if
%>
            <A HREF="<% = mscsPage.URL("product.asp", "sku", _ 
                    predictions(i).sku, "dept_id", Request("dept_id")) %>">
                <% REM Not encoded because HTML %>
                <% = rsProduct("name").Value %>
            </A>
            <br>
<%         end if
                rsProduct.close
            next
        end if
    end if
%>

Figure 3   product.asp


<%@ LANGUAGE=vbscript enablesessionstate=false LCID=1033 %>

<!--#INCLUDE FILE="i_shop.asp" -->
<!--#INCLUDE FILE="i_util.asp" -->

<%
    pf_id = mscsPage.RequestString("pf_id")
    quoted_pf_id = "'" & Replace(pf_id,"'","''") & "'"    REM - add quotes

    REM -- retrieve product:
    sqlText = MSCSQueryMap.product_by_id.SQLCommand
    sqlText = Replace(sqlText, ":1", quoted_pf_id)
    sqlText = Replace(sqlText, ":2", Request("dept_id"))
    cmdTemp.CommandText = sqlText
    Set rsProduct = Server.CreateObject("ADODB.Recordset")
    rsProduct.Open cmdTemp, , adOpenForwardOnly, adLockReadOnly
    
    if rsProduct.EOF then
        product_exists = false
    else
        product_exists = true

        REM -- get fields from recordset
        name = rsProduct("name").value
        description = rsProduct("description").value
        dept_name = rsProduct("dept_name").value
        list_price = rsProduct("list_price").value
        
        sale_price = rsProduct("sale_price").value
        sale_start = rsProduct("sale_start").value
        sale_end = rsProduct("sale_end").value
        
        image_file = rsProduct("image_file").value
        image_width = rsProduct("image_width").value
        image_height = rsProduct("image_height").value
        
        REM -- count used multi-valued attributes:
        max_attr = 5
        nAttr = 0
        Dim attr_label(5)
        for attrNum = 1 to max_attr
            attr_label(attrNum) = rsProduct("attr_label" &  attrNum).value
            if Not IsNull(attr_label(attrNum)) then nAttr = nAttr + 1
        next
        
        rsProduct.Close

        REM -- Log department and product for UA
        Response.AppendToLog "&" & mscsPage.URLArgs("MSS.Request.Category Name", 
	dept_name, "MSS.Request.SKU", pf_id, "
	MSS.Request.Product Name", name)

REM -- determine if product is on sale:
        today = Date
        on_sale = DateDiff("d", today, sale_start) <= 0 and DateDiff("d", today, sale_end) > 0
        
    end if
%>

<HTML>

<HEAD>
    <TITLE><%= displayName %>: Product<% if product_exists then %>: 
	'<%= mscsPage.HTMLEncode(name) %>'<% end if %></TITLE>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
</HEAD>

<BODY
    BGCOLOR="#FFFFFF"
    TEXT=   "#000000"
    LINK=   "#FF0000"
    VLINK=  "#FF0000"
    ALINK=  "#FF0000"
>

<!--#INCLUDE FILE="i_header.asp" -->

<% if Request("error").Count <> 0 then %>
    <FONT COLOR="#FF0000">We're sorry, but this product is 
	not currently available with the attributes you selected.</FONT>
<% end if %>

<% if not product_exists then %>
    <P>The product you requested is currently not available.
<% else %>

<% if Not IsNull(mscsShopperID) then %>

<FORM METHOD=POST ACTION="<%= pageSURL("xt_orderform_additem.asp") %>">

<% else %>
<FORM METHOD=POST ACTION="<%= pageSURL("shopper_lookup.asp") %>">
    <INPUT TYPE=HIDDEN NAME="target" VALUE="xt_orderform_additem.asp">
<% end if %>

    <INPUT TYPE="HIDDEN" NAME="pf_id" VALUE="<%= mscsPage.HTMLEncode(pf_id) %>">
    <INPUT TYPE="HIDDEN" NAME="dept_id" VALUE="<%= Request("dept_id") %>">

<TABLE
    BORDER=     "0"
    CELLPADDING="2"
    CELLSPACING="2"
>
<TR>
    <TD>
        <P><FONT SIZE="6"><B><%= mscsPage.HTMLEncode(name) %></B></FONT>
        
        <% if on_sale then %>
        <P><FONT SIZE="4"><B>ON SALE! <%= MSCSDataFunctions.Money(sale_price) %></B></FONT>
        <P>Regular Price: <%= MSCSDataFunctions.Money(list_price) %>
        <% else %>
        <P><FONT SIZE="4"><B><%= MSCSDataFunctions.Money(list_price) %></B></FONT>
        <% end if %>
        
        <P><%= mscsPage.HTMLEncode(description) %>
        
        <%
        REM -- retrieve single valued attributes:
        cmdTemp.CommandText = Replace(MSCSQueryMap.product_svattrs.SQLCommand, "?", quoted_pf_id)
        Set rsSVAttr = Server.CreateObject("ADODB.Recordset")
        rsSVAttr.Open cmdTemp, , adOpenForwardOnly, adLockReadOnly
        set sva_nameField = rsSVAttr("sva_name")
        set sva_valueField = rsSVAttr("sva_value")
        do while not rsSVAttr.EOF
            %><P><%= sva_nameField.value %>: <%= sva_valueField.value %>
            <% rsSVAttr.MoveNext
        loop
        rsSVAttr.Close %>
        
        <P>
        <INPUT TYPE="Image"
               SRC="<%= "/" & siteRoot %>/manager/MSCS_Images/buttons/btnaddbskt1.gif"
               WIDTH="112"
               HEIGHT="24"
               BORDER="0"
               ALT="Add to Basket"
               ALIGN="MIDDLE">
    </TD>
    <TD>
        &nbsp;
    </TD>
    <TD VALIGN="TOP">
        <% if not IsNull(image_file) then %>
            <IMG SRC="<%= "/" & siteRoot %>/assets/product_images/<%= mscsPage.HTMLEncode(image_file) %>"
                 WIDTH="<% = image_width %>"
                 HEIGHT="<% = image_height %>">
        <% else %>
            Image not available
        <% end if %>
    </TD>
</TR>
</TABLE>

<% if attr_label(1) <> "" then %>
<TABLE>
    <%
    REM -- retrieve multi-valued attributes:
    for attr = 1 to max_attr
        if attr <= nAttr then
            sqlText = MSCSQueryMap.product_mvattrs.SQLCommand
            sqlText = Replace(sqlText, ":1", quoted_pf_id)
            sqlText = Replace(sqlText, ":2", "'" & Replace(attr_label(attr),"'","''") & "'")
            cmdTemp.CommandText = sqlText
            Set rsMVAttr = Server.CreateObject("ADODB.Recordset")
            rsMVAttr.Open cmdTemp, , adOpenForwardOnly, adLockReadOnly
            %>
    <TR>
        <TD><%= attr_label(attr) %>:</TD>
        <TD>
        <SELECT NAME="attr_value<%= attr %>">
        <%
        set mva_valueField = rsMVAttr("mva_value")
        do while Not rsMVAttr.EOF
            %>
            <%= mscsPage.Option(mva_valueField.value, 0) & mva_valueField.value %>
            <% rsMVAttr.MoveNext
        loop
        rsMVAttr.Close
        %>
        </SELECT>
        </TD>
    </TR>
            <%
        end if
    next
    %>

</TABLE>
<% end if %>

</FORM>

<% end if %>

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

    if IsNull(predictor) then
        Response.Write "predictor null"
    end if
    if IsEmpty(predictor) then 
        Response.Write "predictor is empty"
    end if

    if Not IsNull(predictor) and Not IsEmpty(predictor) then 
        set interestlist = Server.CreateObject("Commerce.SimpleList")
        set thisitem = Server.CreateObject("Commerce.Dictionary")
        thisitem.sku = CStr(pf_id)
        thisitem.quantity = 100

        interestlist.add(thisitem)

        set orderformstorage = UtilGetOrderFormStorage()
        set orderform = UtilGetOrderForm(orderformstorage, created)
        set orderitem = orderform.items

        for i = 0 to orderitem.Count - 1
            set thisitem = Server.CreateObject("Commerce.Dictionary")
            thisitem.quantity = orderitem(i).quantity
            thisitem.SKU = orderitem(i).pf_id
            interestlist.add(thisitem)
        next
        set predictions = predictor.GetPredictions(interestlist, 4, 0,1)
        if predictions.Count > 0 then
            header = 0
            for i = 0 to predictions.Count - 1
                cmdTemp.commandText = "select name from newshop_product " _
                    & "where pf_id = '" & Replace(predictions(i).sku,"'", "''") & "'"

                set rsProduct = Server.CreateObject("ADODB.RecordSet")
                rsProduct.Open cmdTemp, , adOpenKeyset, adLockReadOnly
                if rsProduct.RecordCount > 0 then
                    if header = 0 then
                        Response.Write("Other people " _ 
                        & " who have bought this product " _
                        & " have also purchased:")
                        Response.Write("<P>")
                        header = 1
                    end if
            %>
                   <A HREF="<% = mscsPage.URL("product.asp", 
	"pf_id", predictions(i).sku, "dept_id", Request("dept_id")) %>">
                       <% REM Not encoded because HTML %>
                       <% = rsProduct("name").Value %>
                   </A>
                   <br>
         <%     end if
                rsProduct.close
             next
          end if
     end if
%>

<%
REM get related products (if any):
cmdTemp.CommandText = Replace("SELECT prod.pf_id, prod.name, 
	deptprod.dept_id FROM newshop_promo_cross promo_cross, newshop_product prod, 
	newshop_dept_prod deptprod WHERE promo_cross.pf_id = :1 and 
	prod.pf_id = deptprod.pf_id and promo_cross.rel_pf_id = prod.pf_id", ":1", quoted_pf_id)
Set rsRelated = Server.CreateObject("ADODB.Recordset")
rsRelated.Open cmdTemp, , adOpenForwardOnly, adLockReadOnly

REM display up to 5 related products:
if Not rsRelated.EOF then
%>
    <BR>
    <B>See Also</B>
    <%
    nRelated = 0
    set pf_idField = rsRelated("pf_id")
    set nameField = rsRelated("name")
    set dept_idField = rsRelated("dept_id")
    do while Not (rsRelated.EOF Or nRelated >= 5)
        %><BR>
        <A HREF="<% = baseURL("product.asp") & 
	mscsPage.URLShopperArgs("pf_id", pf_idField.value, "dept_id", dept_idField.value) 
	%>"> <% = mscsPage.HTMLEncode(nameField.value) %> </A>
        <%
        nRelated = nRelated + 1
        rsRelated.MoveNext
    loop %>
<% end if %>

<P>
<!--#INCLUDE FILE="i_footer.asp" -->

</BODY>

</HTML>

Figure 5   Identifying Products with pf_id


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

    if IsNull(predictor) then
        Response.Write "predictor null"
    end if
    if IsEmpty(predictor) then 
        Response.Write "predictor is empty"
    end if

    if Not IsNull(predictor) and Not IsEmpty(predictor) then 
        set interestlist = Server.CreateObject("Commerce.SimpleList")
        set thisitem = Server.CreateObject("Commerce.Dictionary")
        thisitem.sku = CStr(pf_id)
        thisitem.quantity = 100

        interestlist.add(thisitem)

        set orderformstorage = UtilGetOrderFormStorage()
        set orderform = UtilGetOrderForm(orderformstorage, created)
        set orderitem = orderform.items

        for i = 0 to orderitem.Count - 1
            set thisitem = Server.CreateObject("Commerce.Dictionary")
            thisitem.quantity = orderitem(i).quantity
            thisitem.SKU = orderitem(i).pf_id
            interestlist.add(thisitem)
        next
        set predictions = predictor.GetPredictions(interestlist, 4, 0.3,2)
        if predictions.Count > 0 then
            header = 0
            for i = 0 to predictions.Count - 1
                cmdTemp.commandText = "select name from newshop_product " -
                    & "where pf_id = '" & Replace(predictions(i).sku,"'",
                    "''") & "'"

                set rsProduct = Server.CreateObject("ADODB.RecordSet")
                rsProduct.Open cmdTemp, , adOpenKeyset, adLockReadOnly
                if rsProduct.RecordCount > 0 then
                    if header = 0 then
                        Response.Write("Other people " _ 
                        & " who have bought this product " _
                        & " have also purchased:")
                        Response.Write("<P>")
                        header = 1
                    end if
%>
                   <A HREF="<% = mscsPage.URL("product.asp", "pf_id", 
                                              predictions(i).sku, "dept_id", 
                                              Request("dept_id")) %>">
                       <% REM Not encoded because HTML %>
                       <% = rsProduct("name").Value %>
                   </A>
                   <br>
<%                 end if
                rsProduct.close
             next
          end if
     end if
%>