calling nvelocity engine

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
RickSilver
Lieutenant (LT)
Lieutenant (LT)
Posts: 66
Joined: Mon Jun 22, 2009 5:49 pm

calling nvelocity engine

Post by RickSilver » Sat Jan 29, 2011 3:27 pm

I am manually obtaining a template and then emailing it in order to replace a custom variable in it. Done this way, it is not automatically run through the nvelocity engine to replace items like store and order information. If my template has this store and order information and my custom variable, is there a single call I can make to get the store and order information, including the itemized list, or do I have to do this replacement and looping myself?

Thanks
Rick

plugables
Captain (CAPT)
Captain (CAPT)
Posts: 276
Joined: Sat Aug 15, 2009 4:04 am
Contact:

Re: calling nvelocity engine

Post by plugables » Mon Jan 31, 2011 6:17 am

You will have to add the Store and Order variables to the nvelocity context.

Code: Select all


        Store store = Token.Instance.Store;
        Order order; // the order object. Initialize it accordingly

        NVelocityEngine nve = NVelocityEngine.Instance;
        Hashtable parameters = new Hashtable();
        parameters.Add("Store", store);
        parameters.Add("Order", order);

        string processedData =  nve.Process(parameters, tmplate);


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

Re: calling nvelocity engine

Post by RickSilver » Mon Jan 31, 2011 7:08 pm

Here is my code. It is NOT replacing the store and order variables. Do you see what I am doing wrong?

Order order = OrderDataSource.Load(e.OrderId, false);
Store store = Token.Instance.Store;
NVelocityEngine nve = NVelocityEngine.Instance;
Hashtable parameters = new Hashtable();
parameters.Add("Store", store);
parameters.Add("Order", order);
emailTemplates[0].Body = nve.Process(parameters, emailTemplates[0].Body);
emailTemplates[0].Send();

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: calling nvelocity engine

Post by mazhar » Fri Feb 04, 2011 8:49 am

When adding parameters in following statements

Code: Select all

parameters.Add("Store", store);
parameters.Add("Order", order);
try to keep parameter names in lowercase and try again like this

Code: Select all

parameters.Add("store", store);
parameters.Add("order", order);

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

Post by RickSilver » Fri Feb 04, 2011 6:35 pm

Thank you Mazhar! That was it. It works now.

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: calling nvelocity engine

Post by mazhar » Mon Feb 07, 2011 4:21 am

Awesome!

Post Reply