Developer forum

Forum » Dynamicweb 10 » Accessing ProductViewModel from Product field type in Item

Accessing ProductViewModel from Product field type in Item

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I have had a similar post related to DW9, but it seems that I always get stuck with this field type.
I have an ItemType (Products) with a property of type ItemRelation (inline), connected to another ItemType (Product).
The second ItemType (Product) has a property of type "Product" allowing the admin to select a product.
I could easily read the first list using Model.Item.TryGetItems("Products", out var products)
This results in a list of ItemViewModel. This ItemViewModel has the property Product that I am trying to read.
In the foreach I have tried:
ProductListViewModel testViewModel = product.GetValue<ProductListViewModel>("Product");

ProductViewModel testViewModel = product.GetValue<ProductViewModel>("Product");

But none of them could produce a non-null result.
What am I missing?

Thank you,
Adrian


Replies

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Anybody?

 
Karsten Thuen Dynamicweb Employee
Karsten Thuen
Reply

Hi Adrian

I am not sure I fully understand your setup. But I tried to replicate, and it works fine. I will try to attach the files for the setup I made.


Best regards
Karsten Thuen

 
Karsten Thuen Dynamicweb Employee
Karsten Thuen
Reply
 
Karsten Thuen Dynamicweb Employee
Karsten Thuen
Reply
This post has been marked as an answer
Votes for this answer: 1
 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Karsten,
Thank you very much for the feedback. I will try your code on my solution and get back to you.

Adrian

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Karsten,
I have compared your code with mine, and they are basically identical.
But that made me investigate further, and I have found the issue. On my project, I am using assortments. The context I was in was anonymous, and none of the assortments would apply to it. I have checked the assortment to work for Anonymous, and everything works!
Thank you very much for spending time on this.

Adrian

 
Karsten Thuen Dynamicweb Employee
Karsten Thuen
Reply

Hi Adrian

No problem. Glad you found the solution.


Best regards
Karsten Thuen

 

You must be logged in to post in the forum