Jaa


How to Target Discounts with the ContentSelector Object

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

You can target discounts on your Web site using the ContentSelector object. You can create code to display discounts using the ContentSelector object the same way that you do for Advertisement objects, except that you specify the "discounts" SelectionContexts pipeline property instead of "advertisements".

The discount properties are controlled through the Discount object definition. For more information about how to define discount properties, see How to Create a Discount.

To display discounts using the ContentSelector object

  1. Use the CommerceContext object to create a ContentSelector object. Supply the "discounts" pipeline to the SelectionContexts property.

  2. Specify a TargetingContextProfile property for the PageGroup object.

  3. Call the GetContent method of the ContentSelector object to select content.

  4. Loop through the returned content to retrieve and display the requested information.

Example

The following code example illustrates how to display targeted discounts with the ContentSelector object. You can add the debug code from How to Run the ContentSelector Object to this example to see pipeline scoring trace messages.

using Microsoft.CommerceServer.Runtime;
using Microsoft.CommerceServer.Runtime.Targeting;
CommerceContext ctx = CommerceContext.Current;
ContentSelector cso = ctx.TargetingSystem.SelectionContexts["discounts"].GetSelector();
ctx.TargetingSystem.TargetingContextProfile["PageGroup"].Value = "All";
cso.ItemsRequested = 1;
StringCollection ads = cso.GetContent();
cso.GetContent();
if (0 == ads.Count)
      Response.Write("No ads returned");
else
      foreach (string s in ads)
         Response.Write(s);