nVelocity access to Order.item.Product.Category.Name

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
voir
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 24
Joined: Mon Jun 09, 2008 4:25 pm
Location: Belingham, WA US

nVelocity access to Order.item.Product.Category.Name

Post by voir » Thu Aug 28, 2008 4:58 pm

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?

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

Re: nVelocity access to Order.item.Product.Category.Name

Post by mazhar » Mon Sep 01, 2008 9:16 pm

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

User avatar
heinscott
Captain (CAPT)
Captain (CAPT)
Posts: 375
Joined: Thu May 01, 2008 12:37 pm

Re: nVelocity access to Order.item.Product.Category.Name

Post by heinscott » Tue Sep 02, 2008 2:43 pm

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

User avatar
voir
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 24
Joined: Mon Jun 09, 2008 4:25 pm
Location: Belingham, WA US

Re: nVelocity access to Order.item.Product.Category.Name

Post by voir » Tue Sep 02, 2008 3:19 pm

:D Cool beans! UR awesome Mazhar, much thanks

User avatar
Shopping Cart Admin
AbleCommerce Admin
AbleCommerce Admin
Posts: 3055
Joined: Mon Dec 01, 2003 8:41 pm
Location: Vancouver, WA
Contact:

Re: nVelocity access to Order.item.Product.Category.Name

Post by Shopping Cart Admin » Tue Sep 02, 2008 3:45 pm

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.
Thanks for your support

Shopping Cart Guru
AbleCommerce.com
Follow us on Facebook

User avatar
voir
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 24
Joined: Mon Jun 09, 2008 4:25 pm
Location: Belingham, WA US

Re: nVelocity access to Order.item.Product.Category.Name

Post by voir » Thu Oct 23, 2008 5:44 pm

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

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

Re: nVelocity access to Order.item.Product.Category.Name

Post by mazhar » Mon Oct 27, 2008 8:51 am

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

Post Reply