Page 1 of 1
Referencing custom data in email template
Posted: Tue Aug 30, 2016 3:18 pm
by RickSilver
How do I go about referencing data I have in a custom sql table in an Email template? Is this possible or must I send the template out myself in code?
Rick
Re: Referencing custom data in email template
Posted: Wed Aug 31, 2016 12:06 am
by jmestep
You can make new nVelocity objects, but that is pretty complicated and there isn't a whole lot of info out on nVelocity. There are some posts on AC wiki-
http://wiki.ablecommerce.com/index.php/ ... city&go=Go
I have created new template parameters based on some custom classes, but have still had to send the email via code or via the send email page in the admin where I have added code to populate custom variables, something like the following. There is still coding involved but the email can be sent manually.
Code: Select all
if (Request.QueryString["OrderNumber"] != null)
{
int orderNumber = AlwaysConvert.ToInt(Request.QueryString["OrderNumber"]);
int orderId = OrderDataSource.LookupOrderId(orderNumber);
CommerceBuilder.Orders.Order order = OrderDataSource.Load(orderId);
Hashtable customParameters = xxxCustomEmailParameters.GetAllCustomTemplateVariablesForOrder(order);
foreach (DictionaryEntry entry in customParameters)
{
if (!mergeTemplate.Parameters.Contains(entry))
{
mergeTemplate.Parameters.Add(entry.Key, entry.Value);
}
}
}
Then in the email template I have code like:
Code: Select all
#set($itemvar="")
#foreach($itemvar in $itemvariables)
..........
#set ($itemstatus = $itemvar.itemstatus)
#if($itemstatus.Length>0)
Status: $itemstatus
#end
Re: Referencing custom data in email template
Posted: Wed Aug 31, 2016 1:59 pm
by RickSilver
Thanks. Any idea why I'm not getting emails? I've verified emailTemplate is not null. Nothing in spam.
EmailTemplate emailTemplate = EmailTemplateDataSource.Load(1);
if (emailTemplate != null)
{
emailTemplate.Parameters["recipient"] = "
rsilver@gmail.com";
emailTemplate.ToAddress = "
rsilver@gmail.com";
emailTemplate.Send();
}
Re: Referencing custom data in email template
Posted: Thu Sep 01, 2016 4:30 am
by nadeem
Try setting up the store to make sure it is not null. Your code becomes something like:
Code: Select all
EmailTemplate emailTemplate = EmailTemplateDataSource.Load(1);
if (emailTemplate != null)
{
emailTemplate.Parameters["recipient"] = "rsilver@gmail.com";
emailTemplate.ToAddress = "rsilver@gmail.com";
emailTemplate.Parameters["store"] = AbleContext.Current.Store;
emailTemplate.Send();
}