Custom email templates

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
WylieE
Captain (CAPT)
Captain (CAPT)
Posts: 281
Joined: Tue Mar 25, 2008 8:26 am
Location: Puyallup, WA
Contact:

Custom email templates

Post by WylieE » Fri Oct 31, 2008 3:19 pm

I must be missing something very simple here.

Due to the highly custom nature of our products, we often send order acknowledgements to our customers. These emails spell out the order along with payment and warranty terms and conditions. Sales reps will send these out after reviewing the order contents.

I've been building the email templates and I'm stumped on two items. The email needs to include the sales reps name and I've trying to include this as:

Best regards,<br>
$user.Name<br>
$store.Name<br>

nVelocity is not converting $user.name to the name. I've tried $user.FirstName and $user.UserName with the same results. What I get in the email is the text '$user.name' Shouldn't this work anywhere in the store? Or have I botched the syntax somehow?

Additionally, we would like to include custom text based on the shipping method selected that includes average shipping times and potential customs verbiage. I'm guessing we'll need to create a scriptlet and call that from the email template?

Thanks so much.
Eric Wylie
Warmoth Guitar Products, Inc.
http://www.warmoth.com

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Custom email templates

Post by AbleMods » Fri Oct 31, 2008 10:11 pm

WylieE wrote:$user.Name<br>
$store.Name<br>

nVelocity is not converting $user.name to the name. I've tried $user.FirstName and $user.UserName with the same results. What I get in the email is the text '$user.name' Shouldn't this work anywhere in the store? Or have I botched the syntax somehow?
Try $Order.user.name
Additionally, we would like to include custom text based on the shipping method selected that includes average shipping times and potential customs verbiage. I'm guessing we'll need to create a scriptlet and call that from the email template?
Scriptlets cannot be called from email templates. However you can do some customer IF-THEN commands in the email templates via nVelocity. Look at some of the templates and you'll see how the syntax is done.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

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

Re: Custom email templates

Post by mazhar » Mon Nov 03, 2008 6:53 am

You can get the user name from user or order object as below.

Code: Select all

$user.UserName
or
$order.User.UserName
The above code will show store user name which will be the Email address of the user. if you want to show full name the composition of first and last name then it will be as below

Code: Select all

$user.PrimaryAddress.FirstName $user.PrimaryAddress.LastName 
or
$order.User.PrimaryAddress.FirstName $order.User.PrimaryAddress.LastName 

User avatar
WylieE
Captain (CAPT)
Captain (CAPT)
Posts: 281
Joined: Tue Mar 25, 2008 8:26 am
Location: Puyallup, WA
Contact:

Re: Custom email templates

Post by WylieE » Tue Nov 04, 2008 11:38 am

Excellent. $order.User.UserName worked just fine.

Have a great day folks!
Eric Wylie
Warmoth Guitar Products, Inc.
http://www.warmoth.com

User avatar
WylieE
Captain (CAPT)
Captain (CAPT)
Posts: 281
Joined: Tue Mar 25, 2008 8:26 am
Location: Puyallup, WA
Contact:

Re: Custom email templates

Post by WylieE » Wed Nov 05, 2008 12:02 pm

OK, now I'm really starting to scratch my head. I'm working on the shipping text. I've taken a copy of the Customer Order Notification and added this to the top:

<html>
<p><b>Order Acknowledgement<br>
(Confirmation Request)</b></p>

<p>Dear $order.BillToFirstName,</p>

<p>Thank you very much for your order, # $order.OrderId. To better assure accuracy and your satisfaction, we would like your confirmation before we start production. Please carefully review the details of your order below and respond with your confirmation or with any changes you might require. This is your last opportunity to make changes freely. We will await your confirmation before we go to production. <br>
Please note that custom work is not refundable, but it is fully covered by our warranty.
</p>
<p><i>Payment Terms:</i> After we have received your confirmation we will charge your credit card for the Order Total shown below then we will begin production. Please verify that you have the funds available on your credit card before you confirm the order.</p>

<p><i>Ship Method: </i> $shipment.ShipMethodName</p>

<p><i>Estimated production time:</i> Eight to ten weeks from receipt of your confirmation.</p>

<p>Please let me know if you have any questions or further needs. I will be glad to help. <br>
I look forward to your reply.</p>

<p>Best regards,<br>
$order.user.PrimaryAddress.FirstName $order.user.PrimaryAddress.LastName <br>
$store.Name</p>

The order notification template uses the $shipment.ShipMethodName field. I just copied the field and added it to the new text but it doesn't resolve. It works properly in the order notification code chunk, but not in the text I've added. I've also tried it as ${shipment.ShipMethodName} and it doesn't work either. I've also tried $shipment.ShipMethodID with no results. I'm guessing I'm missing something simple????? But I can't find it, argh! What do I need to change?
Eric Wylie
Warmoth Guitar Products, Inc.
http://www.warmoth.com

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

Re: Custom email templates

Post by mazhar » Wed Nov 05, 2008 12:56 pm

That's because there is no $shipment available in your custom template. In the Order notification the $shipment is extracted by looping through the available shipments for that order. In order to make it work in your custom Email template try the following code

Code: Select all

#foreach($shipment in $order.Shipments)
p><i>Ship Method: </i> $shipment.ShipMethodName</p>
#end

User avatar
WylieE
Captain (CAPT)
Captain (CAPT)
Posts: 281
Joined: Tue Mar 25, 2008 8:26 am
Location: Puyallup, WA
Contact:

Re: Custom email templates

Post by WylieE » Wed Nov 05, 2008 5:12 pm

Ah, that helps. Thank you very much.

I've been trying to nest an If/elseif/end statement inside the #foreach loop and nVelocity doesn't seem to like that.

Example:
#foreach($shipment in $order.Shipments)
<p><i>Ship Method: </i>
#{If} ($shipment.ShipMethodName =="UPS Ground")
After we ship your order UPS will email you with the tracking number.
#{end}</p>
#end

I'm getting a error when attempting to send the email: Encountered "#end\r\n" at line 17, column 1. This only happens when I add the if/then code. I'm guessing the #foreach statement is grabbing the first #end statement and leaving the #if unterminated. I've dug through several of the templates and have yet to find an example of nested statements like this.

Edit: Encapsulating the if/end in brackets eliminates the error, but then the code is not interpreted.
Last edited by WylieE on Wed Nov 05, 2008 6:08 pm, edited 1 time in total.
Eric Wylie
Warmoth Guitar Products, Inc.
http://www.warmoth.com

User avatar
WylieE
Captain (CAPT)
Captain (CAPT)
Posts: 281
Joined: Tue Mar 25, 2008 8:26 am
Location: Puyallup, WA
Contact:

Re: Custom email templates

Post by WylieE » Wed Nov 05, 2008 5:41 pm

On a related note, I'm also working on an order summary for our sales staff. They would like to see the payments including credit card amount and authorization number.

The Customer Order Notification template includes payment method and I copied that block. However, I've noticed nothing is being returned from the Customer Order Notification.

#foreach($payment in $payments)
$payment.PaymentMethodName<br />
$payment.ReferenceNumber<br />
#end

I've tried several orders that have payments and none of them are displaying the payment method or reference number. Can anyone confirm this email template is working for them? This is turning in to one of those days when nothing works right....
Eric Wylie
Warmoth Guitar Products, Inc.
http://www.warmoth.com

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

Re: Custom email templates

Post by mazhar » Thu Nov 06, 2008 5:41 am

Ah, that helps. Thank you very much.

I've been trying to nest an If/elseif/end statement inside the #foreach loop and nVelocity doesn't seem to like that.

Example:
#foreach($shipment in $order.Shipments)
<p><i>Ship Method: </i>
#{If} ($shipment.ShipMethodName =="UPS Ground")
After we ship your order UPS will email you with the tracking number.
#{end}</p>
#end

I'm getting a error when attempting to send the email: Encountered "#end\r\n" at line 17, column 1. This only happens when I add the if/then code. I'm guessing the #foreach statement is grabbing the first #end statement and leaving the #if unterminated. I've dug through several of the templates and have yet to find an example of nested statements like this.

Edit: Encapsulating the if/end in brackets eliminates the error, but then the code is not interpreted.
Try the following code

Code: Select all

#foreach($shipment in $order.Shipments)
<p>
<i>Ship Method: </i>
#if($shipment.ShipMethodName == "Your Shipping Method Name")
Your Custom Message Here
#end
</p>
#end

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

Re: Custom email templates

Post by mazhar » Thu Nov 06, 2008 6:00 am

On a related note, I'm also working on an order summary for our sales staff. They would like to see the payments including credit card amount and authorization number.

The Customer Order Notification template includes payment method and I copied that block. However, I've noticed nothing is being returned from the Customer Order Notification.

#foreach($payment in $payments)
$payment.PaymentMethodName<br />
$payment.ReferenceNumber<br />
#end

I've tried several orders that have payments and none of them are displaying the payment method or reference number. Can anyone confirm this email template is working for them? This is turning in to one of those days when nothing works right....
Make sure that $payments is available in the template or you can just try the following code by extracting the $payment from $order.Payments as below

Code: Select all

#foreach($payment in $order.Payments)
$payment.PaymentMethodName<br />
$payment.ReferenceNumber<br />
#end

User avatar
WylieE
Captain (CAPT)
Captain (CAPT)
Posts: 281
Joined: Tue Mar 25, 2008 8:26 am
Location: Puyallup, WA
Contact:

Re: Custom email templates

Post by WylieE » Thu Nov 06, 2008 12:13 pm

mazhar wrote:
On a related note, I'm also working on an order summary for our sales staff. They would like to see the payments including credit card amount and authorization number.

Make sure that $payments is available in the template or you can just try the following code by extracting the $payment from $order.Payments as below

Code: Select all

#foreach($payment in $order.Payments)
$payment.PaymentMethodName<br />
$payment.ReferenceNumber<br />
#end
I think I might be getting a clue here... I also need to show the payment authorization number, which is in the transactions table. Do I need to nest another #foreach inside the one above in order to retrieve the auth# in the transactions table?
Eric Wylie
Warmoth Guitar Products, Inc.
http://www.warmoth.com

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

Re: Custom email templates

Post by mazhar » Thu Nov 06, 2008 12:23 pm

Yes if the $transactions is not available then you can loop through the $payment.Transactions and extract $transaction.

User avatar
WylieE
Captain (CAPT)
Captain (CAPT)
Posts: 281
Joined: Tue Mar 25, 2008 8:26 am
Location: Puyallup, WA
Contact:

Re: Custom email templates

Post by WylieE » Thu Nov 06, 2008 2:53 pm

mazhar wrote:Yes if the $transactions is not available then you can loop through the $payment.Transactions and extract $transaction.
Apologies for so many follow-up questions. I thought I was getting the hang of this.

Code: Select all

#foreach($transactions in $payments.Transactions)
$transactions.AuthorizationNumber
#end
I've tried it as $transaction and $transactions, nested the code inside the #foreach payment loop and outside the loop, also tried referencing $order.payments.Transactions. Also tried $payment and $payments. None of those attempts generated an error, but none of them displayed the auth#. Admittedly, I'm guessing on the field name based on the SQL tables.

I've been through the AC wiki, the forums here and the Apache nVelocity site looking at code examples and docs. What I don't see is documentation on the field names. Are most users going through the .Net pages to find the fields?
Eric Wylie
Warmoth Guitar Products, Inc.
http://www.warmoth.com

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

Re: Custom email templates

Post by mazhar » Fri Nov 07, 2008 6:28 am

You can access following variables with $transaction

Code: Select all

Amount
AuthorizationCode
AVSResultCode
CAVResultCode
CVVResultCode

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

Re: Custom email templates

Post by mazhar » Fri Nov 07, 2008 6:34 am

I've been through the AC wiki, the forums here and the Apache nVelocity site looking at code examples and docs. What I don't see is documentation on the field names. Are most users going through the .Net pages to find the fields?
NVelocity code just contains the object we pushed in the parameters. For example if the we talk about the order parameter that actually contains the CommerceBuilder.Orders.Order object. You can easily check that what this object will contain using the Visual Studio. For example if you want to know about the data contained by order object.

1)- Click the Object Browser from the View menu of Visual Studio.
2)- In the Object Browser left sidebar select the CommerceBuilder.Orders Namespace.
3)- Select the Order class in the sidebar and it will list all the information about class.

If some one is not using the Visual Studio then he can get the same information through API documentation available here.
ftp://ftp.ablecommerce.com/evals/Commer ... 7_Help.zip
Image

User avatar
BryanWarmoth
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 44
Joined: Fri May 23, 2008 11:24 am
Location: Puyallup, Wa
Contact:

Re: Custom email templates

Post by BryanWarmoth » Tue Nov 11, 2008 1:13 pm

Is it possible to send our own parameters to the email template as well? We have another object that we would like to send with the order object for the order confirmation email. If it is possible, where should i add the code to pass our own object to the email?
Bryan Bingham
Warmoth Guitar Products Inc.
bryan@warmoth.com
http://www.warmoth.com

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

Re: Custom email templates

Post by mazhar » Tue Nov 11, 2008 1:21 pm

For this you have to send your Email manually as below
viewtopic.php?f=42&t=8571
You can place the code for this in the Load function of the RecieptPage.

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

Re: Custom email templates

Post by mazhar » Tue Nov 11, 2008 1:25 pm

A most suitable place for this is the CheckedOut method of the ConLib/OnePageCheckout control.

User avatar
BryanWarmoth
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 44
Joined: Fri May 23, 2008 11:24 am
Location: Puyallup, Wa
Contact:

Re: Custom email templates

Post by BryanWarmoth » Tue Nov 11, 2008 6:29 pm

Worked perfectly! Thanks!
Bryan Bingham
Warmoth Guitar Products Inc.
bryan@warmoth.com
http://www.warmoth.com

Post Reply