Skip to content

Instantly share code, notes, and snippets.

@vkoppaka
Created February 13, 2013 21:57
Show Gist options
  • Save vkoppaka/4948736 to your computer and use it in GitHub Desktop.
Save vkoppaka/4948736 to your computer and use it in GitHub Desktop.
A custom formatter class to add custom fields to the order confirmation email template
using System;
using System.ComponentModel;
using Telerik.Sitefinity;
using Telerik.Sitefinity.Ecommerce.Orders.Model;
using Telerik.Sitefinity.Modules.Ecommerce.Orders.Business;
using Telerik.Sitefinity.Modules.Ecommerce.Orders.Interfaces;
using Telerik.Sitefinity.Modules.Ecommerce.Orders.Web.UI.CheckoutViews;
namespace SitefinityWebApp
{
public class OrderConfirmationEmailTemplateFormatterWithCustomFields : OrderConfirmationEmailTemplateFormatterBase, IOrderConfirmationEmailTemplateFormatter
{
public string ReplaceValuesInTemplate(string template, CheckoutState checkoutState, Order order)
{
string currentTemplate = ReplaceValuesInTemplateBase(template, checkoutState, order);
var properties = TypeDescriptor.GetProperties(order);
foreach (PropertyDescriptor property in properties)
{
var metaProperty = property as MetafieldPropertyDescriptor;
if (metaProperty == null)
continue;
if (metaProperty.Name == "GiftMessage")
{
object value = metaProperty.GetValue(order);
if (value != null)
{
currentTemplate = currentTemplate.Replace("%%GIFTMESSAGE%%", value.ToString());
}
else
{
currentTemplate = currentTemplate.Replace("%%GIFTMESSAGE%%", "N/A");
}
}
}
return currentTemplate;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment