Jump to content

Prestashop default sorty by and similar products


Recommended Posts

The default sort by in prestashop is by product id (the one that is named "--") I would like to change it to completly random products, after trying to do this for the whole day, im going nowhere close, so i need some help please.

 

I was able to achieve something similar on home featured, by replacing the following code

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

 

with

 

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100);
 if ($products) {
 shuffle($products);
 array_splice($products, ($nb ? $nb : 10));
 }

 

 

Im guessing i can do same to product sorty by and change the default, '--' to random.

 

 

Also this is a bit random but i need to customize similar products, when you are viewing a product. it only shows 4 products and i would like to change that, and randomize it more. I just cant find which file even i have to edit.

 

Thanks in advance,

Link to comment
Share on other sites

Ok I found out how to make other products in the same category more random than it was (it was constantly 4 same things at some point)

 

what i did was i added the following line to productcategory.php

 

 // Get infos
 $categoryProducts = $category->getProducts((int)($cookie->id_lang), 1, 1000);
 $sizeOfCategoryProducts = (int)sizeof($categoryProducts);
 $middlePosition = 0;

/* new code*/
 shuffle($categoryProducts); //This randomizes products.

 

 

Only problem is it displays only 4 products out of the category, and i really need it to be 6. I'm assuming the change would be in productcategory.php or in productcategory.tpl I just cant find exactly where, and i just started learning php. Any one have a clue?

Link to comment
Share on other sites

  • 1 month later...
×
×
  • Create New...