Developer forum

Forum » Development » Accessing IndexExtender data in Product Catalog for ViewModel Template

Accessing IndexExtender data in Product Catalog for ViewModel Template

John Broers
Reply

Can values added via an IndexExtender be used in a Product Catalog for ViewModel template?

We've implemented an IndexExtender and added a custom value to the Product Indexer. We're using a Product Catalog for ViewModel app to display products and would like to show this custom value in the product blocks.

Is there a way to access and display this extended value within a ProductViewModel?

Any guidance or examples would be appreciated.


BR,

John


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi John

That is not easily possible - the index is used for searching - and if values are not stored, they cannot be retrieved.

Your IndexExtender probably has some logic related to the value - if you extract that to a method, you can create an extension method for the productviewmodel that has the same logic:

public static string GetCustomValue(this ProductViewModel productViewModel){...}

Alternatively you need to find the paragraph settings, find the repository and index, load the index, find the product based off the autoid in the index using a query, get the document from the search result and find the value in a stored field..... Lots of code and lots of potential performance issues.

Another solution again is to create a custom field on a product and move your IndexExtender logic into a SQL task that will update that custom field on the product - then it will be indexed and be available in your templates.

BR Nicolai

 

You must be logged in to post in the forum