Developer forum

Forum » Ecommerce - Standard features » Recently viewed products list is not populated

Recently viewed products list is not populated

Fredrik
Fredrik
Reply

Hello

I am trying to make a list of recently viewed products, but the collection is not populated. What do I have to do to activate it? (v 9.12.0.0)

I use the code below:

var youHaveSeenTheseProductsList = new Dynamicweb.Ecommerce.Specialized.RelatedProductListProviders.YouHaveSeenTheseProductsList();
var products = youHaveSeenTheseProductsList.GetCollection(new RelatedProductListProviderEventArgs());

Best regards,
Fredrik


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Frederik

I am not sure you can use that anymore - it is depending on old analytics and old product catalog module which are both being faced out. So if you are using the new viewmodel version of the product catalog it cannot work.

It is super simple to do custom any ways:

First in your product detail template add a string array to session:

if (Cache.Current["RelatedProductListProviderTypes"] is null)
            {
                Context.Current.Session.Add("youHaveSeenTheseProductsList", new string[] { "prod1" });
            }
            else
            {
                var productIds = ((string[])Dynamicweb.Context.Current.Session["youHaveSeenTheseProductsList"]).ToList();
                productIds.Add("prod2");
                Context.Current.Session["youHaveSeenTheseProductsList"] = productIds.ToArray();
            }

And then fetch them something like this:

if (Cache.Current["RelatedProductListProviderTypes"] is null)
            {
                if (Context.Current.Session["youHaveSeenTheseProductsList"] != null)
                {
                    var productIds = (string[])Dynamicweb.Context.Current.Session["youHaveSeenTheseProductsList"];
                    var youHaveSeenTheseProductsList = Dynamicweb.Ecommerce.Services.Products.GetByProductIDs(productIds, false, Common.Context.LanguageID, true, true);
                }
            }

BR Nicolai

Votes for this answer: 1
 
Fredrik Pelli
Fredrik Pelli
Reply

Thank you, it works now.

 

You must be logged in to post in the forum