Load a Product Template Field for a Product

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
rmaweb
Commander (CMDR)
Commander (CMDR)
Posts: 118
Joined: Fri Sep 10, 2010 9:41 am

Load a Product Template Field for a Product

Post by rmaweb » Fri Jun 05, 2015 5:33 am

Hello,

I am working on some site customization and I was wondering if there was a method or an nhibernate call to be able to load the value of a specific product template field for a product. As opposed to using

Code: Select all

List<ProductTemplateField> templateFields = (from tf in product.TemplateFields
                                                         where tf.InputField.Name == "xxx"
                                                         select tf).ToList();
and having to do a foreach loop to get the field I want. Is there a way to skip the List and get the value directly?
Ryan A.
Scott's Bait and Tackle
http://store.scottsbt.com
Work In Progress
Able Gold R10
Bootstrap 3.3

jguengerich
Commodore (COMO)
Commodore (COMO)
Posts: 436
Joined: Tue May 07, 2013 1:59 pm

Re: Load a Product Template Field for a Product

Post by jguengerich » Fri Jun 05, 2015 6:26 am

I think you could do:

Code: Select all

string myValue = product.TemplateFields.Where(tf => tf.InputField.Name == "xxx").Select(f => f.InputValue).First();
You'll need "using System.Linq;" if you don't have it already. This also makes the assumption that there is a field named "xxx", so you may want to add a little defensive programming, perhaps using FirstOrDefault() instead of First(). I didn't test this code.

EDIT: using the query syntax, I guess that would be:

Code: Select all

            string theValue = (from tf in product.TemplateFields
                                                         where tf.InputField.Name == "xxx"
                                                         select tf.InputValue).First();  // see also .Single()/.SingleOrDefault()
Jay

rmaweb
Commander (CMDR)
Commander (CMDR)
Posts: 118
Joined: Fri Sep 10, 2010 9:41 am

Re: Load a Product Template Field for a Product

Post by rmaweb » Fri Jun 05, 2015 7:07 am

Thank you Jay,

I will give this a shot. I have no experience with nhibernate queries or Linq, so thank you for pointing me in the right direction.
Ryan A.
Scott's Bait and Tackle
http://store.scottsbt.com
Work In Progress
Able Gold R10
Bootstrap 3.3

Post Reply