Developer forum

Forum » Templates » Enumerating Product Fields / Product Category Fields from an item_type dropdown list

Enumerating Product Fields / Product Category Fields from an item_type dropdown list

Stephen Jackson
Reply

Hello.

I am trying to develop a generic item type for displaying a product or product category field.

I have defined an item type with a "Product Field" (Drop down) and Style field (Text), and created the follow SQL Query as the source for the dropdown

SELECT concat(FieldCategoryId, '->', FieldId) as Label, 
concat(FieldCategoryId, ':', FieldId) as Value
FROM EcomProductCategoryField 
where FieldPresentationType=1

This will get all the non-reference fields for product categories, split the category and field name on the " : ", and allow someone to simply select which field they want when dropping the item type into a page with a product catalog app.  ( fieldValue = product.ProductCategories[FieldCategoryId].Fields[FieldId].Value.ToString(); )

HOWEVER. 

I am not sure how to do this dynamically for the system types, as these can be simple fields in the ecom_products table (price), or complex types (Manufacturer) spanning multiple tables.

So I cannot just do a 

fieldValue = product.ProductCategories[FieldCategoryId].Fields[FieldId].Value.ToString(); as I intend to do with the product category fields.

Does anyone have any tips on how to enumerate and display the built-in types in a generic way?

I really dont want to have to do in the template, a massive switch with 200 'case "FieldName": value = path.in.view.model.to.name;' 

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Stephen,

 

If you need it in a SQL you can do SELECT ProductFieldName, ProductFieldSystemName FROM EcomProductField

 

That will give you both the system and the custom fields.

 

Best Regards,

Nuno Aguiar

 
Stephen Jackson
Reply

Thanks Nikolai. But I cannot use that in the Item_Type dropdown list data sources AFAIK?

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Stephen 

No, that you cannot. Maybe you can query the schema of ecomproducts table?

SELECT  COLUMN_NAME FROM  INFORMATION_SCHEMA.COLUMNS WHERE  TABLE_NAME = 'EcomProducts'
 
Stephen Jackson
Reply

Hi Nicolai.

I had the same thought, and tried a schema query from the firehose interface, but it returned no resultset for some reason

 

You must be logged in to post in the forum