Developer forum

Forum » Development » Outputting Custom ProductFields in ProductViewModel

Outputting Custom ProductFields in ProductViewModel

Søren Ravn Lund
Reply

Hello,

I have this ProductField (1.png) & (2.png)

I would like to output the Colors in my template which inherits ProductCatalogue.ProductViewModel

 

If I iterate over Model.ProductFields.Values: (3.png)

I get the following (4.png)

If I field.Value I get the type: System.Collections.Generic.List`1[Dynamicweb.Ecommerce.ProductCatalog.FieldOptionValueViewModel]

 

Can I somehow get the colors out without having to parse the JSON?

 

 

1.png 2.png 3.png 4.png

Replies

 
Søren Ravn Lund
Reply

Okay, found out that I can cast the Model.ProductFields.Values.Value as a List<FieldOptionValueViewModel>.

Let me know if that aren't the preferablable approach.

 
Lars Larsen
Lars Larsen
Reply
This post has been marked as an answer

Hi Søren

You can get the product field values using: product.ProductFields["Name of product field"].Value

Product is a product from the ProductViewModel

Votes for this answer: 1

 

You must be logged in to post in the forum