Programming Display Windows - Static Version [Part II]
If you followed the last post you now have a brand new DisplayTemplate on the marketing system with three properties: ProductImage, ProductTitle and ProductPrice.
Before creating new advertisements and associate the new DisplayTemplate we will need an expression. This expression will be used to filter only advertisements for a determined display window.
To do that, we need two steps:
- Create a new targeting context attribute called BillBoard using the Commerce Server Manager.
- Create a new global expression to be used on the Target Expressions of the advertisements that we will create on the next post. :)
Step 1
- Open the Commerce Server Manager and navigate to Commerce Server Manager/Global Resources/Profiles(<Your Server>_StarterSite_Profiles)/Profile Catalog/Profile Definitions/Targeting Context
- On the right side of the window, click Add.
- Select Add New Property and click OK.
- Fill the boxes Name and DisplayName with BillBoard.
- Very important!!! Click Apply and on the small diskette icon on the top of the Commerce Server Manager.
- Your profile definition will be like the following picture:
Step 2
Great. Now we have a new TargetingContext property. It's time to create a new global expression. This expression will be associated to the advertisement and will be used during the content selection to filter only advertisements fitting to our display window.
The following code can be used on a Console Application to create the appropriate global expression:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.CommerceServer;
using Microsoft.CommerceServer.Marketing;
using System.Xml;
namespace CreateGlobalExpression
{
class Program
{
static void Main(string[] args)
{
// Set the URL to the Web service.
string marketingWebServiceUrl = @"http://localhost/MarketingWebService/MarketingWebService.asmx";
// Create an instance of the Marketing System agent.
MarketingServiceAgent ma = new MarketingServiceAgent(marketingWebServiceUrl);
MarketingContext marketingSystem = MarketingContext.Create(ma);
//Creating the global expression
XmlDocument xmlDoc = new XmlDocument();
XmlElement clause = xmlDoc.CreateElement("CLAUSE");
clause.SetAttribute("OPER", "equal");
XmlElement property = xmlDoc.CreateElement("PROPERTY");
property.SetAttribute("ID", "TargetingContext.BillBoard");
property.SetAttribute("TYPE", "STRING");
XmlElement immedval = xmlDoc.CreateElement("IMMED-VAL");
immedval.SetAttribute("TYPE", "STRING");
XmlElement value = xmlDoc.CreateElement("VALUE");
value.InnerText = "MainDisplayWindow";
immedval.AppendChild(value);
clause.AppendChild(property);
clause.AppendChild(immedval);
// Create a new expression.
Expression ex = marketingSystem.Expressions.NewExpression(false);
ex.Description = "BillBoard Select Expression";
ex.Body = clause;
ex.Name = "BillBoard";
ex.Category = "TargetCondition";
ex.Save(true);
}
}
}
The attachment has a zip file with a console application to create the expression.
See you later, Cris.
This posting is provided "AS IS" with no warranties, and confers no rights.