2

I am fairly new in using NVelocity. I am trying to edit some of the old templates for my company and i ma getting this error which i dont understand. OK so in template, if order has multiple shipments then show multiple shipment name and if only one then show only one shipment name. when there is multiple shipments, it works fine BUT when there is only one then somehow template does not renders the required shiment name instead printout the class name.

 #if($order.Shipments.Count > 1) 
 #foreach($shipment in $order.Shipments)
 #beforeall 
 #each 
 $shipment.ShipMethodName <strong>|</strong> 
 #else
 $order.Shipments[0].ShipMethodName  // in emails it renders "Orders.OrderShipmentCollection[0].ShipMethodName"
 #end
 #end

Please help.

patel.milanb
  • 5,822
  • 15
  • 56
  • 92
  • Sorry if stupid question, but your _else_ clause seems to just handle the 0 shipment case. Am I wrong ? – jbl Sep 05 '13 at 16:08
  • yes...thats right ....i have edited the question... it seems that its still not working... – patel.milanb Sep 06 '13 at 08:15
  • 1
    I'm with @jbl, confused by your if statement that has "> 0" rather than "> 1". You've also edited an error into the template because it is now missing an #end statement for the foreach. If you aren't aware NVelocity will usually write out the template variable reference (e.g. "$order.Shipments[0].ShipMethodName") when something is null or fails, but it shouldn't write out the type names. I'd try printing out "$order.Shipments[0]" and debug the data being passed through. – Jonathon Rossi Sep 06 '13 at 12:55

1 Answers1

1

I know this is an old question, but in case someone is looking for a solution later I thought I'd post an answer as I was going through old questions that don't have accepted answers. I don't how I didn't notice the error when I posted that comment in September last year.

$order.Shipments[0].ShipMethodName is giving you Orders.OrderShipmentCollection[0].ShipMethodName because NVelocity doesn't support indexers like C#, you need to use the get_Item() method, i.e. $order.Shipments.get_Item(0).ShipMethodName that is the underlying method the C# compiler creates for indexers.

What is happening is $order.Shipments prints out the type name (Orders.OrderShipmentCollection) and the rest [0].ShipMethodName just gets printed verbatim.

Jonathon Rossi
  • 4,149
  • 1
  • 22
  • 32