Page 1 of 1
nVelocity access to Order.item.Product.Category.Name
Posted: Thu Aug 28, 2008 4:58 pm
by voir
I need to access the Category a product was purchased from in order emails and Receipt page(s)
I tried
Code: Select all
foo
...
#foreach($orderItem in $order.Items)
#foreach($itemCategory in $orderItem.Product.Categories)
$itemCategory.Name
...
blah
but it didn't work, is there an easier way?
Re: nVelocity access to Order.item.Product.Category.Name
Posted: Mon Sep 01, 2008 9:16 pm
by mazhar
Use the following code
Code: Select all
#foreach($pcid in $orderItem.Product.Categories)
#foreach($sc in $store.Categories)
#if($sc.CategoryId == $pcid)
$sc.Name
#end
#end
#end
in place of the following line
Code: Select all
#foreach($itemCategory in $orderItem.Product.Categories)
$itemCategory.Name
Re: nVelocity access to Order.item.Product.Category.Name
Posted: Tue Sep 02, 2008 2:43 pm
by heinscott
Is there a way of knowing what NVelocity variables are available on any given page on Able? I'm having trouble figuring this out, even though it seems pretty straight forward. For instance, I am on my Members/MyOrder.aspx?OrderId=74 page, and I wanted to include tracking numbers on the page (I don't really want to do this here, but, for this scenario, lets assume that I do.) Now, in accordance with other documentation (as well as the email templates), I thought that I had the variable "$order" available to represent that particular order. Is this not true? I was not able to use it at all, even though this page is dedicated to a particular order. Just for the sake of testing, I tried $order.OrderId... only to have it printed as "$order.OrderId" on the page.
My $store variable works, so, you can see how I would be confused. Ultimately, I want to include tracking numbers in my Order Completed emails, but, that should be easy once I get past this first step.
Thanks for the help.
Scott
Re: nVelocity access to Order.item.Product.Category.Name
Posted: Tue Sep 02, 2008 3:19 pm
by voir

Cool beans! UR awesome Mazhar, much thanks
Re: nVelocity access to Order.item.Product.Category.Name
Posted: Tue Sep 02, 2008 3:45 pm
by Shopping Cart Admin
Hello Scott,
The velocity syntax is for emails and code snippets, you can reference our CommerceBuilder api guide for the information you're looking for use in the .aspx pages.
Re: nVelocity access to Order.item.Product.Category.Name
Posted: Thu Oct 23, 2008 5:44 pm
by voir
Update:My goal was to use Category.Summary to hold important messages per category to be displayed in the confirmation email, on the recieptpage, viewmyorder and printmyorder For example
- Handcrafted items from peru take 8-10 weeks for delivery
... the conlib locations were easy I created a control GetCategoryMessagesbyOrderId.ascx that took an orderid looped through got all unique messages and returned a string with them all in it ... nVelocity was a bit harder, I couldn't figure out how to add to an array only if the item wasn't already in the array ... if only I could call [[conlib:GetCategoryMessagebyOrderId OrderId=$order.OrderId]] inside the email template ... oh well, this is what I ended up doing instead:
Code: Select all
#set ($messages = [])
#foreach($orderItem in $order.Items)
#foreach($itemCategory in $orderItem.Product.Categories)
#foreach($pcid in $orderItem.Product.Categories)
#foreach($sc in $store.Categories)
#if($sc.CategoryId == $pcid)
#set($Contains = 0)
#foreach($tempMessage in $messages)
#if($tempMessage == $sc.Message)
#set($Contains=1)
#end
#end
#if ($Contains==0)
#set ($messages = [$messages,$sc.Summary])
#end
#end
#end
#end
#end
#end
#foreach($displayMessage in $messages)
$displayMessage
#end
Re: nVelocity access to Order.item.Product.Category.Name
Posted: Mon Oct 27, 2008 8:51 am
by mazhar
Try this code
Code: Select all
#foreach($orderItem in $order.Items)
#foreach($pcid in $orderItem.Product.Categories)
#foreach($c in $store.Categories)
#if($c.CategoryId == $pcid)
$c.Summary
#end
#end
#end
#end