Product Custom Fields in Email

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
jsmits
Lieutenant (LT)
Lieutenant (LT)
Posts: 66
Joined: Wed Sep 30, 2009 11:57 am

Product Custom Fields in Email

Post by jsmits » Mon Nov 23, 2009 8:30 am

Is it possible to access ProductCustomFields through NVelocity for purposes of displaying in an email template?

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

Re: Product Custom Fields in Email

Post by mazhar » Mon Nov 23, 2009 8:57 am

Yes possible do something like this

Code: Select all

$product.CustomFields["CustomFieldName"].FieldValue

User avatar
jsmits
Lieutenant (LT)
Lieutenant (LT)
Posts: 66
Joined: Wed Sep 30, 2009 11:57 am

Re: Product Custom Fields in Email

Post by jsmits » Tue Nov 24, 2009 7:48 am

Sorry Mazhar, I can't quite seem to get it.

What I tried was:

Code: Select all

$orderItem.Product.CustomFields["Availability"].FieldValue
And this is the output:

CommerceBuilder.Products.ProductCustomFieldCollection["Availability"].FieldValue

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

Re: Product Custom Fields in Email

Post by mazhar » Tue Nov 24, 2009 8:15 am

EDIT MADE

Hmm give a try to this

Code: Select all

$orderItem.Product.CustomFields.get_Item('Availability').FieldValue
or if each product has only single product custom field then

Code: Select all

$orderItem.Product.CustomFields.get_Item(0).FieldValue

User avatar
jsmits
Lieutenant (LT)
Lieutenant (LT)
Posts: 66
Joined: Wed Sep 30, 2009 11:57 am

Re: Product Custom Fields in Email

Post by jsmits » Tue Nov 24, 2009 8:39 am

The latter worked so it doesn't look like get_Item will work by passing in the FieldName. For now my products only have the 'availability' field, but in the future they may have more. In that case I guess it might be possible to loop through them and only display the ones I need.

Thanks for your help.

User avatar
jsmits
Lieutenant (LT)
Lieutenant (LT)
Posts: 66
Joined: Wed Sep 30, 2009 11:57 am

Re: Product Custom Fields in Email

Post by jsmits » Thu Mar 18, 2010 10:41 am

Mazhar,

I know I am resurrecting an old thread, but I found a bug with the solution. If the item doesn't have a custom field then the email generation crashes as the index is out of range.

I tried to check if( $orderItem.Product.CustomFields.get_item(0) != null) and encountered the error:

Encountered "null" at line 102, column 64.
Was expecting one of:
"[" ...
"(" ...
<STRING_LITERAL> ...
"true" ...
"false" ...
<NUMBER_LITERAL> ...
<IDENTIFIER> ...
"{" ...
"!" ...
;

What is the proper way to check to see if the collection is null?

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

Re: Product Custom Fields in Email

Post by mazhar » Thu Mar 18, 2010 11:03 am

Try this one instead

Code: Select all

#if($orderItem.Product.CustomFields.Count > 0)
$orderItem.Product.CustomFields.get_Item(0).FieldValue
#end

User avatar
jsmits
Lieutenant (LT)
Lieutenant (LT)
Posts: 66
Joined: Wed Sep 30, 2009 11:57 am

Re: Product Custom Fields in Email

Post by jsmits » Thu Mar 18, 2010 11:06 am

Bingo! thx.

Post Reply