Page 1 of 1

nVelocity - Adding comments to emails

Posted: Tue May 12, 2009 2:08 pm
by WylieE
Hi everyone,

I am trying to add code to our order confirmation emails based on shipment weight. Depending on the total weight of the order, we need to include additional instructions to our order packers. Just a simple if statement, but I'm having problems with the syntax. I've read through the Commercebuilder library docs.

I've tried $shipment.TotalWeight, $orderitem.TotalWeight and order.Items.TotalWeight.

Code: Select all

#if($shipment.TotalWeight() < 4)
First Class Instructions
#end
Does this need to be encapsulated in some sort of #foreach statement?

Thanks!

Re: nVelocity - Adding comments to emails

Posted: Wed May 13, 2009 3:15 am
by mazhar
You need to port following code to NVelocity

Code: Select all

LSDecimal orderWeight;
            foreach (OrderShipment orderShipment in _Order.Shipments)
            {
                LSDecimal shipmentWeight = orderShipment.OrderItems.TotalWeight();
                orderWeight += shipmentWeight;
            }

Re: nVelocity - Adding comments to emails

Posted: Wed May 13, 2009 9:48 am
by nickc
$shipment.OrderItems.TotalWeight()

Re: nVelocity - Adding comments to emails

Posted: Wed May 13, 2009 11:00 am
by WylieE
Thanks guys.

I tried Nick's string and couldn't get it to work.

Mazhar's code would imply I need to generate a total weight. If this is the case, what is the purpose of TotalWeight() and under what conditions can it be used?

I'll work on Mazhar's code. Any other suggestions folks?

Re: nVelocity - Adding comments to emails

Posted: Wed May 13, 2009 12:56 pm
by nickc
Hmm. My string definitely returns a value. You might be running into a problem with your comparison - there's a known issue with Able's LSDecimal class in respect to nVelocity - see viewtopic.php?f=42&t=8717 for a workaround.

Re: nVelocity - Adding comments to emails

Posted: Wed May 13, 2009 1:41 pm
by WylieE
Got it to work. Just re-keyed it. nVelocity mojo, I suppose.

Thanks everyone.