In this post is described a way how Email Campaign Manager personalization fields could be extended with calculated fields. By default you can output user profile fields that are present in /sitecore/templates/Modules/EmailCampaign/ Subscriber template. You can use this profile fields in email by using profile names that are surrounded by dollar signs(e.g.: $firstname$, $lastname$). Calculated user profile fields could be useful when you want to output data based on current date.
Sitecore Email Campaign Manager has a lot of abilities to be extended. One of the ways to extend it is change TypeResolver in Sitecore.EmailCampaign.config:
<TypeResolver type="YourNamespace.TypeResolver, YourAssembly" singleInstance="true" />
You are able to override in TypeResolver functions:
In our case we override GetCorrectContactProfile function:
The new ContactProfile is inherited from Sitecore.Modules.EmailCampaign.ContactProfile:
Now you are able to use your own calculated values for personalization of emails.
Sitecore Email Campaign Manager has a lot of abilities to be extended. One of the ways to extend it is change TypeResolver in Sitecore.EmailCampaign.config:
<TypeResolver type="YourNamespace.TypeResolver, YourAssembly" singleInstance="true" />
You are able to override in TypeResolver functions:
ContactList CreateCorrectContactList(string systemName) Contact GetCorrectAnonymouseFromEmail(string email, ManagerRoot root) Contact GetCorrectContactFromName(string userName) ContactList GetCorrectContactListFromName(string contactListName) ContactProfile GetCorrectContactProfile() ManagerRoot GetCorrectManagerRootObject(Item rootItem) LocalSettingsBase GetCorrectLocalSettingsObject(ManagerRoot root) MessageItem GetCorrectMessageObject(Item item) PostalEngineBase GetCorrectPostalEngine() TargetAudience GetCorrectTargetAudience(Item item)
In our case we override GetCorrectContactProfile function:
namespace YourNamespace { /// <summary> /// Extended Type Resolver to return extended contact profile /// </summary> public class TypeResolver : Sitecore.Modules.EmailCampaign.Core.TypeResolver { /// <summary> /// Gets the correct contact profile. /// </summary> /// <returns></returns> public override Sitecore.Modules.EmailCampaign.ContactProfile GetCorrectContactProfile() { return new ContactProfile(); } } }
The new ContactProfile is inherited from Sitecore.Modules.EmailCampaign.ContactProfile:
namespace YourNamespace { /// <summary> /// Contact profile extended with ability to get calculated user profile properties /// </summary> public class ContactProfile : Sitecore.Modules.EmailCampaign.ContactProfile { /// <summary> /// Gets a named property value. /// </summary> /// <param name="propertyName">Name of the property. /// </param> /// <returns> /// The value. /// </returns> protected override object GetPropertyValueCore(string propertyName) { //Here should be your code that will calculate Contact Profile value } /// <summary> /// Gets or sets a profile property value indexed by the property name. /// </summary> /// <param name="propertyName">The name of the profile property.</param> /// <returns> /// The value of the specified profile property, typed as object. /// </returns> public override string this[string propertyName] { get { //Here should be your code that will calculate Contact Profile value } set { base[propertyName] = value; } } } }
Now you are able to use your own calculated values for personalization of emails.
No comments:
Post a Comment