Developer forum

Forum » Dynamicweb 9.0 Upgrade issues » Problem with Item type field "Product"

Problem with Item type field "Product"

Lasse Hove Nielsen
Lasse Hove Nielsen
Reply

Hi,

We're trying to create a spot-product selector using the item type Product, to select a single product to display - we're running 9.10.13.

But it seem the item only returns a productId-like string instead of a Product, something like => p_10861622: when I call eg. PageView.Current().Page.Item["SpotProduct"]. I've tried to cast it to a product but no dice.

We can't use the productservice either, as the ID should be 10861622 without the p_ and :

Is this a bug or am I just doing it wrong?

2021-08-10_15-00-14.png

Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer

Hi Lasse,

The value you see is the encoded value that the Item Editor uses to track whether the you picked products or groups: p_{ID} for products and g_{ID} for groups.

You should consider using the view models to get at these values. The item itself will contain the raw data, whereas the view models add additional functionality on top. Using an ItemViewModel instead, you can call the GetValue method, which will give you a list of ProductViewModel. They contain a lot of product information that you can use in your template, or -- if necessary - you can get the full product from the ProductService since the model contains the ID.

- Jeppe

Votes for this answer: 1
 
Lasse Hove Nielsen
Lasse Hove Nielsen
Reply

Hi Jeppe,

Ah thanks for the directions - worked like a charm

 

/Lasse

 

You must be logged in to post in the forum