Created
February 13, 2013 21:57
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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