Developer forum

Forum » Ecommerce - Standard features » ProductListViewModel - Primary Variant Id

ProductListViewModel - Primary Variant Id

Lasse Hove Nielsen
Lasse Hove Nielsen
Reply

Hi,

I'm working with the ProductViewModel and needs to be able to access the Primary Variant Id on the products. I can't find it in the module Product Properties - just wondering if there are any way I can access it by default means or if it could be added på the properties?


Replies

 
Nicolai Pedersen
Reply

You can use the product service to get the product object. I guess you refer to DefaultVariantComboID

Can you tell what you need it for - the problem you are trying to solve. Not sure adding a property on the productviewmodel is the best solution. I might prefer a solution where the VariantInfo property gets an indication of your chosen variant combination.

BR Nicolai

 
Lasse Hove Nielsen
Lasse Hove Nielsen
Reply

Yes defaultVariantComboId - I need it to create a new custom product model of the product, and to do that I need the productId, variantId and defaultVariantComboId - the defaultVariantComboId determines which variant to use in GetProductById if the variantId is empty.

 
Nicolai Pedersen
Reply

Hi Lasse

Then I will ask why again - why do you need to create this new custom product model? You describe a solution - I would like to understand the 'end' problem so we can come up with the best way of solving it.

Are you on a product list and what to show something else than the product (master product?) that you get from the model?

Thanks for clarifying!

BR Nicolai

 
Jesper Holm Damgaard
Reply

Hi Guys

It is on a product list where we need to show the default variant - not the master product.

We need to add some business logic on how to display the product name, number, and a bunch of other stuff.

To avoid duplicating that logic into multiple templates, we prefer to have it in a custom product view model.

Makes sense?

--
All the best, Jesper

 
Jesper Holm Damgaard
Reply

Any thoughts on this?

All the best, Jesper

 
Kevin Steffer
Kevin Steffer
Reply

I'd guess we can come up with a lot of other standard things that could be needed on the ProductViewModel for example all the other data on stored fields from the Index, database table coloumns etc.

Maybe it would be worth looking into giving the ProductViewModel a Properties property of type IEnumerable<Dictionary<string, object>>.

Then give us a NotificationSubscriber hook into a FillProductViewModel() method where we could a reference to the data source - is this case a link to lucene document and the database row representing the source..

We could then add the collection of extra needed information into the Properties collection from what we need from our sources.

 

You must be logged in to post in the forum