Welcome to MSDN Blogs Sign in | Join | Help

Cristiano WebLog

Microsoft Infrastructure & Development Tips and Tricks
Programming Display Windows - Static Version [Part I]

In order to create a static display window supported by the Commerce Server 2007 Marketing System we need a custom DisplayTemplate.

I'll use the DisplayTemplate to format a set of DIVs for each shopping window position. An associated CSS file will be used on the future ASCX control to format the appearance of the window according to your taste.

Let's use the following code to create the DisplayTemplate. Remember, I'm using a vanilla StarterSite installation and all webservices referenced are pointing to the localhost.

//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);

//Create a new ad display template.
DisplayTemplate template = marketingSystem.DisplayTemplates.NewDisplayTemplate();
template.Name = "ShoppingWindowItem";
template.Text = "<div id=\"ShoppingWindowAD\"><div id=\"ProductImage\"><img src=\"{%ProductImage%}\"></div><div id=\"ProductTitle\">{%ProductTitle%}</div><div id=\"ProductPrice\">{%ProductPrice%}</div><div id=\"More\">More...</div></div>";

//Create the "ProductImage" property for the new template.
DisplayProperty pi = new DisplayProperty("ProductImage");
pi.Label = "ProductImage";
pi.Source = TemplatePropertySource.Auto;

//Create the "ProductTitle" property for the new template.
DisplayProperty pt = new DisplayProperty("ProductTitle");
pt.Label = "ProductTitle";
pt.Source = TemplatePropertySource.Auto;

//Create the "ProductPrice" property for the new template.
DisplayProperty pp = new DisplayProperty("ProductPrice");
pp.Label = "ProductPrice";
pp.Source = TemplatePropertySource.Auto;

//Add the properties to the template.
template.Properties.Add(pi);
template.Properties.Add(pt);
template.Properties.Add(pp);

//Save the template.
template.Save();

I've packed all the necessary code to create the DisplayTemplate on the attached ZIP file. 

See you on the next post on associating the DisplayTemplate to the product advertisements.

Cris.

This posting is provided "AS IS" with no warranties, and confers no rights.

Posted: Tuesday, July 03, 2007 12:35 AM by crisag

Attachment(s): CreateDisplayTemplate.zip
Anonymous comments are disabled
Page view tracker