blingblingpow Posted February 19, 2010 Share Posted February 19, 2010 Is it possible to get random products on the main category page?For example:Category - CheeseProducts are listed in the order they were added.I want to change it so that all the products are listed in a random order. Link to comment Share on other sites More sharing options...
chow Posted April 13, 2010 Share Posted April 13, 2010 I am interested to know as well. Anyone? Link to comment Share on other sites More sharing options...
rocky Posted April 14, 2010 Share Posted April 14, 2010 The easiest way is to change line 59 of category.php (in Prestashop v1.2.5) from: $cat_products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay); to: if ($orderBy == 'position') $cat_products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay, false, false, true, 1000000); else $cat_products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay); This code will randomly choose up to 1000000 products from the category when the sort option is "--". When any other sort option is selected, the products are not sorted randomly. The reason I chose 1000000 is that there is no "unlimited" parameter, so I chose a number that is unlikely to be exceeded. Further code modifications would be required to make it truly unlimited. Link to comment Share on other sites More sharing options...
tomcat80 Posted June 14, 2010 Share Posted June 14, 2010 Hi!I would need this function, but it didn't work for me. I think because I use a filter module. (Filter Search Community Edition v2.1)I think modifications needs in product-list.tpl (I don't know, because I'm not a programmer..)product-list.tpl: {if isset($products)} <!-- Products list --> {foreach from=$products item=product name=products key=key} {if ($product.allow_oosp OR $product.quantity > 0)}{l s='Available' mod='filtersearch'}{else}{l s='' mod='filtersearch'}{/if}getImageLink($product.link_rewrite, $product.id_image, 'home')}" alt="{$product.legend|escape:'htmlall':'UTF-8'}" /> {if $product.new == 1}{l s='new' mod='filtersearch'}{/if}{$product.name|truncate:35:'...'|escape:'htmlall':'UTF-8'} {$product.description_short|strip_tags:'UTF-8'|truncate:360:'...'} {if $product.on_sale}{l s='On sale!' mod='filtersearch'} {elseif ($product.reduction_price != 0 || $product.reduction_percent != 0) && ($product.reduction_from == $product.reduction_to OR ($smarty.now|date_format:'%Y-%m-%d' <= $product.reduction_to && $smarty.now|date_format:'%Y-%m-%d' >= $product.reduction_from))}{l s='Price lowered!' mod='filtersearch'} {/if}{l s='View' mod='filtersearch'} {/foreach} <!-- /Products list -->{/if} Could somebody help me in that?I use PS 1.2.5 Stablemy page: http://chiks.huThanks!!!The easiest way is to change line 59 of category.php (in Prestashop v1.2.5) from: $cat_products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay); to: if ($orderBy == 'position') $cat_products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay, false, false, true, 1000000); else $cat_products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay); This code will randomly choose up to 1000000 products from the category when the sort option is "--". When any other sort option is selected, the products are not sorted randomly. The reason I chose 1000000 is that there is no "unlimited" parameter, so I chose a number that is unlikely to be exceeded. Further code modifications would be required to make it truly unlimited. Link to comment Share on other sites More sharing options...
guest* Posted February 5, 2011 Share Posted February 5, 2011 This code will randomly choose up to 1000000 products from the category when the sort option is "--". When any other sort option is selected, the products are not sorted randomly. The reason I chose 1000000 is that there is no "unlimited" parameter, so I chose a number that is unlikely to be exceeded. Further code modifications would be required to make it truly unlimited. I don't have this option "--" in version 1.3.3. So how can I improve this ? Link to comment Share on other sites More sharing options...
rocky Posted February 5, 2011 Share Posted February 5, 2011 Do you have the following on line 15 of pagination.tpl in your theme's directory? {l s='--'} This is the -- option I mentioned. Link to comment Share on other sites More sharing options...
guest* Posted February 6, 2011 Share Posted February 6, 2011 No, and also not in original presta-template. So I will add this now. Shall this option appear on BO at preferences > products as a value ? Because it is not there to choose.It now appears on pagination after product-listing of my products in first row. On the row before I have the filter-options which customer can choose:--price: lower firstprice: higher firstname: A to Zname: Z to Aon stock firstWhat I want is that by each refresh the product-list shows not by default or other filter but products as random. Acutal presta version is 1.3.6. Link to comment Share on other sites More sharing options...
rocky Posted February 8, 2011 Share Posted February 8, 2011 You should have the following options on the Prefrences > Products tab for "Default order by":Product nameProduct priceProduct added datePosition inside categoryManufacturerProduct modified date Link to comment Share on other sites More sharing options...
yesiam Posted March 1, 2011 Share Posted March 1, 2011 Rocky thank you very much, works perfectly in prestashop 1.3.6 !Greetings Link to comment Share on other sites More sharing options...
ryanwhitlie Posted March 26, 2011 Share Posted March 26, 2011 I was looking to order categories and subcategories as random, not products. The project was a restaurant directory in Switzerland and they didn't want to be seen to promote any restaurant in particular, so they wanted the results to come up randomly.I solved it by doing the following:Open /classes/Category.phpLine 419, changeORDER BY `level_depth` ASC, c.`position` ASC');toORDER BY RAND();');This seemed to do the trick!I hope this helps anyone looking for this. Link to comment Share on other sites More sharing options...
guest* Posted March 27, 2011 Share Posted March 27, 2011 I was looking to order categories and subcategories as random, not products. The project was a restaurant directory in Switzerland and they didn't want to be seen to promote any restaurant in particular, so they wanted the results to come up randomly.I solved it by doing the following:Open /classes/Category.phpLine 419, changeORDER BY `level_depth` ASC, c.`position` ASC');toORDER BY RAND();');This seemed to do the trick!I hope this helps anyone looking for this. does not work for me.... It delivers a 500 site... In which prestaversion did you added ? Link to comment Share on other sites More sharing options...
ryanwhitlie Posted March 27, 2011 Share Posted March 27, 2011 does not work for me…. It delivers a 500 site… My bad, didn't write it properly. Testament to the value of copy&paste;replace with this:ORDER BY RAND();'); Link to comment Share on other sites More sharing options...
ryanwhitlie Posted March 27, 2011 Share Posted March 27, 2011 Ah, the formatting when posting messes it up.Let me try that again. ORDER BY RAND();'); Even this is wrong when I use tag.Basically you need to write ORDER BY RAND then with no space afterwards open and close brackets, semicolon, close single quote, close bracket then another semicolon. All with no space after RAND.I hope this helps I'm sure there's a better way but I'm not much of a coder Link to comment Share on other sites More sharing options...
guest* Posted March 27, 2011 Share Posted March 27, 2011 Same problem and same code. What should it be between the ; and ) An apostrophe, or an accent ? Link to comment Share on other sites More sharing options...
guest* Posted March 27, 2011 Share Posted March 27, 2011 post overlapped, also the ORDER BY RAND(); not working and ending in 500. Link to comment Share on other sites More sharing options...
guest* Posted March 27, 2011 Share Posted March 27, 2011 Ah, the formatting when posting messes it up.Basically you need to write ORDER BY RAND then with no space afterwards open and close brackets, semicolon, close single quote, close bracket then another semicolon. All with no space after RAND. Hi this one works, but no random for me... Link to comment Share on other sites More sharing options...
ryanwhitlie Posted March 27, 2011 Share Posted March 27, 2011 Same problem and same code. What should it be between the ; and ) An apostrophe, or an accent ? Ok sorry about this folks, seems there's no way to add an apostrophe to these posts. The apostrophe should be between the (); and );Again with no spaces. Link to comment Share on other sites More sharing options...
guest* Posted March 27, 2011 Share Posted March 27, 2011 I added an apostrophe, but it is no random. I changed also on BO the pereferences into Positions into category. Also no random for me. Perhaps IIS don't understand the code ? I don't know. The only random what I got working is on tag block. Link to comment Share on other sites More sharing options...
erginaktasw Posted January 19, 2014 Share Posted January 19, 2014 How can we do this on newest prestashop version 1.5.x ? I really need products to be listed randomly in all categories and front page. Please help Link to comment Share on other sites More sharing options...
klymets1 Posted February 7, 2014 Share Posted February 7, 2014 How can we do this on newest prestashop version 1.5.x ? I really need products to be listed randomly in all categories and front page. Please help +1 also want to know how to display randomly goods category page? Link to comment Share on other sites More sharing options...
karthikcs Posted December 16, 2015 Share Posted December 16, 2015 I found the way to display random products in category page on PS 1.6.2Go to classes>Category.php In the line 688public function getProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null) change "$random = false" to "$random = true" and set $random_number_products = 1 to the number of products you want to show in random. In my store I've set to display 80 products per page, so I've set $random_number_products = 1 to $random_number_products = 80. Note: If you set the random number of products to large number, page loading time increase. Try to put the random to lowest possible. 2 Link to comment Share on other sites More sharing options...
knoose Posted February 14, 2016 Share Posted February 14, 2016 This worked for me! thanx Link to comment Share on other sites More sharing options...
dirsubmit Posted July 13, 2016 Share Posted July 13, 2016 HI Guys, No matter what I do and change in /classes/Category.php nothing changes on my front-end. Cache disabled, cleared. $random set true .. even modified the SQL statements and add order by clauses.. no matter what.. the products in the categories come up the same exact way.. is something overriding what I'm doing? Does anybody have any clues as to why and where I should look? Using PS V 1.5.6.2 Thanks! Link to comment Share on other sites More sharing options...
zaioncola Posted June 27, 2017 Share Posted June 27, 2017 Same for me - doesn't work - please help! The only thing that partly worked is : shuffle($products); added to product-list.tpl - but it shuffles product within one product page (so if I have 12 prods - they're displayed random) - I want all the products within category to shuffle Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now