Referencing custom data in email template

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
RickSilver
Lieutenant (LT)
Lieutenant (LT)
Posts: 66
Joined: Mon Jun 22, 2009 5:49 pm

Referencing custom data in email template

Post by RickSilver » Tue Aug 30, 2016 3:18 pm

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

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Referencing custom data in email template

Post by jmestep » Wed Aug 31, 2016 12:06 am

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
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

RickSilver
Lieutenant (LT)
Lieutenant (LT)
Posts: 66
Joined: Mon Jun 22, 2009 5:49 pm

Re: Referencing custom data in email template

Post by RickSilver » Wed Aug 31, 2016 1:59 pm

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

}

nadeem
Captain (CAPT)
Captain (CAPT)
Posts: 258
Joined: Tue Jul 31, 2012 7:23 pm

Re: Referencing custom data in email template

Post by nadeem » Thu Sep 01, 2016 4:30 am

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

}

Post Reply