Jump to content

Random products on 1.5


Recommended Posts

I recommend not to use any random alike modules/mods with your shops unless you have less than a few products.

The infamous ORDER BY RAND() is a performance killer.

 

Now if you get weird layout, check cache, tpls, carriage return after the '?>' closing tag and the like.

Link to comment
Share on other sites

Hi, i need to randomize from all products not from featured only. I used this code:

$nb1 = 20;

$products = $category->getProducts((int)($params['cookie']->id_lang), 1, ($nb1 ? $nb1 : 10));

if ($products) { shuffle($products); array_splice($products, ($nb ? $nb : 10)); }

 

but it randomize only from featured not from all products and it shows products badly:

post-84835-0-45578400-1352027717_thumb.png

Link to comment
Share on other sites

Exactly what I mean about performance killing code.

 

When we want to get a random set (w/ or w/o feature) we do something like:

select x,y,z

from t

order by rand()

limit n;

 

This add a pseudo column to the select then order it by this pseudo (random) column and finaly extract just the n first elements.

 

The more product you have, the more the bubble sort based on the pseudo column will have to work and this computation tend to be exponential. I usually address randomization thru a set of scheduled database creation of subset but this is nothing Prestashop standard and requires some privileges that may not be available depending on your hoster.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...