Developer forum

Forum » Development » Custom ViewModel gets added to PIM feeds automaticly

Custom ViewModel gets added to PIM feeds automaticly

Mads Poulsen
Mads Poulsen
Reply

Hi, 

We've noticed, that when adding a CustomProductViewModel that inherits from ProductViewModel, it automaticlly gets added to the PIM Feed.
They aren't listed within "Included Properties", but still shows in the feed. (Combined screenshot attached)

We can fix that they appear by adding xmlignore to the property, but still not control it from the backend.

How is this supposed to work? Are we missing a property that makes them controlable from within the "excluded/included properties"?

pim-feed.jpg

Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Mads

A suggestion would be to not extend the viewmodel and use extension methods instead - in your example you add a property but really it is a method - a less intrusive implementation would be to make an extension method instead.

public static string GetProductNameShort(this ProductViewModel product)

Which in the template would be 

@Model.GetProductNameShort()

The feature with not returning properties when not included is handled by how we fill the properties of the view model - we have a BulkCreateView method in our ViewEngine that will take a look at the filledproperties settings passed in:

You should be able to do something like this:

var productViewModelType = typeof(CustomProductViewModel);
var propertyFiller = new ViewModelPropertyFiller<CustomProductViewModel>(settings.FilledProperties, productViewModelType);
propertyFiller.Fill(model, nameof(model.ProductNameShort), () => yourLogic());

BR Nicolai

 

You must be logged in to post in the forum