Developer forum

Forum » Ecommerce - Standard features » Related products with viewmodel ProductCatalog.

Related products with viewmodel ProductCatalog.

Simon Nordahl
Simon Nordahl


 I'm having difficulties finding the native way of finding the related products on the product page, after swapping to the refactored new product viewmodels introduced in 9.7 (?).

I'm currently working on a 9.9 installation.


There does no longer seem to be any relatedproduct collection on the viewmodel.

Is the inteded way now to call the relatedproduct service to fetch the related products? If yes, then what is the recommended way of finding the product price (including discounts) for the related products?


Kind regards



Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen

Hi Simon

No, they are currently not there and we are hesitant to add them. Issue is that some implementations add products as related products getting into some serious performance issues which we want to avoid.

  1. The best way to load related products is to search them and load them async from the frontend using a hidden page that returns the related products - either as json or just using rendered (partial) markup. This will uitilize the index, give you a regular list of products with all the information needed to render them, and you can delay loading until the product detail page is fully loaded and maybe wait untill the related section scrolls into view.
  2. Alternatively get the products using the API,
    1. Get all the related products using the API.
    2. Then load all prices for all related products: PriceManager.PreparePrices(products);
    3. Get the price for each product: PriceManager.GetPrice(product, currency, CountryCode, UserId);
    4. Get the discounts for each product: 
      var discounts = new Orders.Discounts.DiscountInfoCollection(product, currency, CountryCode, UnitId, UserId, ShopId);
      return discounts.TotalPrice;
    5. Deduct the discount total from the product price using Price.Subtract()

BR Nicolai

Simon Nordahl
Simon Nordahl

Fast response as always Nicolai :)

Fair point regarding the potential performace pitfall. 

I will probably end up going with solution1, but just a question for solution 2; why not have a central Dynamicweb service with your posted price logic instead of us having to do this manually? I just fear the day a breaking change comes around and we have to correct our price logic.






You must be logged in to post in the forum