Developer forum

Forum » Templates » random products from querypublisher

random products from querypublisher

Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi

we need to get 3 random products from at a productgroup via querypublisher. I presume this can not be done with configuration.

And i have been trying to wrap my head around how to do it in a template, but can´t get it to work.

Any suggestions, or anyone got a template doing just this?

/Hans


Replies

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Nevermind, just found a super simple solution

 

@{
var originalLoop=@GetLoop("QueryResultItem");
var shuffled = originalLoop.OrderBy(x => Guid.NewGuid()).ToList();
}
 
@foreach (LoopItem i in shuffled.Take(3))
{
// do my stuff here
}

 

You must be logged in to post in the forum