Developer forum

Forum » Development » Reverse last viewed products

Reverse last viewed products

Tom Kamphuis
Reply

Hi guys,

In the DW templates we have the option to iterate through the last viewed products using the tagname "eCom:Related.YouHaveSeenTheseProducts". We're looking for a way to reverse the output of this loop and then take 12 from those products to a different list, as shown below:

const int rpvShowMax = 12;
var recentlyViewedProducts = GetLoop("eCom:Related.YouHaveSeenTheseProducts");
recentlyViewedProducts.Reverse();
recentlyViewedProducts = recentlyViewedProducts.Take(rpvShowMax).ToList();

Is there any way to not do this in Razor? Like building the logic in a ProductListExtender or a Provider? And are there any coding examples?

Cheers!
Tom


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
This post has been marked as an answer

Hi Tom,

You can find the source code for the provders here: http://developer.dynamicweb.com/downloads/source-code.aspx (in Dynamicweb.eCommerce.Specialized.zip). They are fairly simple to implement, and I think all you need to do is change the SQL statement.

Hope this helps,

Imar

 

Votes for this answer: 1
 
Tom Kamphuis
Reply

Hi Imar,

It sure helps! What I actually did is inherit the provider I needed the data from. This way I can use everything DW created and top it off with a little custom logic, as in the example shown below.

[RelatedProductList("eCom:Related.ReverseYouHaveSeenTheseProducts")]
    public class ReversedSeenProductListProvider : YouHaveSeenTheseProductsList
    {
        private const int MaxProductListSize = 12;
 
        public override ProductCollection GetCollection(RelatedProductListProviderEventArgs eventArgs)
        {
            var collection = base.GetCollection(eventArgs).ToList();
 
            collection.Reverse();
            collection = collection.Take(MaxProductListSize).ToList();
 
            var returnCollection = new ProductCollection();
            returnCollection.AddRange(collectionfalse);
 
            return returnCollection;
        }
    }

Cheers,
Tom

 

You must be logged in to post in the forum