Developer forum

Forum » Development » Render related products on lists

Render related products on lists

Anders Ebdrup
Reply

Hi DW,

 

I have some trouble to render my related products on the lists which is loaded by use of a custom RelatedProductListProvider.

So how can I use this standard extensibility without have to use various template extenders and notification subscribers?

 

Best regards, Anders


Replies

 
Morten Bengtson
Reply

Hi Anders,

You probably just need to add an attribute on the class, where you provide the template loop name that DW will use when it renders the list of products.

Read more about it here: Related product list providers. You can also download Dynamicweb.eCommerce.Specialized.zip, which contains the source code for the standard providers.

Another option is to configure a Smart Search and then attach that as related searches to groups or products. No coding required :)

Read more about it here: Related searches.

BR, Morten

 
Anders Ebdrup
Reply

Hi Morten,

 

Thanks for your quick answer as always! :-) My related product provider works fine when displaying a single product, but the related products are not avaiable in the lists.

And that is here that I think, it should be possible to mark on my related product provider whether these informations should be rendered on the lists if the tag is available and not a decision made by DW.

 

Best regards, Anders

 
Morten Bengtson
Reply

DW will provide different parameters to your provider depending on whether it is rendering a product list (eventArgs.Products) or product details (eventArgs.Product).

[RelatedProductList("MyRelatedProducts")]
public class MyRelatedProducts : RelatedProductListProvider
{
    public override ProductCollection GetCollection(RelatedProductListProviderEventArgs eventArgs)
    {
        if (eventArgs.Product != null)
        {
            // product details
        }
        else if (eventArgs.Products != null)
        {
            // product list or order/cart
        }
    }
}

The related products are only fetched from your provider if the template loop exists in the current template. If thats not the case on your DW installation then it might be a bug.

Are you trying to render a list of related products for each product in a list? I haven't tried that before, so I'm not sure how to do that :)

 
Anders Ebdrup
Reply

Hi Morten,

 

Exactly, but it does not seem to be working for the product lists as related products seems to be discarded and not rendered even though the information is loaded from the RelatedProductProvider.

 

Best regards, Andes

 
Morten Bengtson
Reply

There are some product details (e.g. reviews/comments, related products, etc.) that are only available on the product details page. These details are not made available for each product inside a product list which most likely is due to the performance issues it would cause.

So, out of the box, you can render related products for either a complete product list or for a single product, but you cannot render related products for each product inside a product list.

I guess the answer to your problem is the same as for most questions on this forum... use razor templates ;-)

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Anders and Morten

Morten assumptions are right. It is like this due to performance issues.

An easy solution is using a product template extender which is there for both lists and detail views.

Nicolai

Votes for this answer: 1
 
Anders Ebdrup
Reply

Hi Nicolai,

 

Still it would make sense for me to decide whether my custom related products should be shown on the lists and not a decision by the system.

But for now I have changed the implementation to a "ProductListBeforeRender"-subscriber and use a template extender.

 

Best regards, Anders

 

You must be logged in to post in the forum