Page 1 of 2

How to show "random" products on homepage instead of latest?

Posted: Fri Jul 24, 2009 5:02 am
by itrends
How to show "random" products on homepage instead of latest?

Anyone? :)

Re: How to show "random" products on homepage instead of latest?

Posted: Sat Jul 25, 2009 3:35 am
by itrends
Anyone tonight? :)

Re: How to show "random" products on homepage instead of latest?

Posted: Sat Jul 25, 2009 3:37 am
by Qphoria
change the sql query for getLatestProducts to use order by rand

Re: How to show "random" products on homepage instead of latest?

Posted: Thu Jul 30, 2009 6:44 am
by fivepix
Qphoria wrote:change the sql query for getLatestProducts to use order by rand
Hi Qphoria,

I'm a new when it comes to php can you please provide an example code of what needs to be change?

Thanks!

Re: How to show "random" products on homepage instead of latest?

Posted: Thu Jul 30, 2009 8:27 am
by Qphoria
EDIT: catalog/model/catalog/product.php

FIND this function:

Code: Select all

public function getLatestProducts($limit) {
INSIDE THAT Function, FIND:

Code: Select all

ORDER BY p.date_added
REPLACE WITH:

Code: Select all

ORDER BY rand()

Re: How to show "random" products on homepage instead of latest?

Posted: Fri Jul 31, 2009 5:01 am
by fivepix
Qphoria Awesome! much appreciated Thanks!

Re: How to show "random" products on homepage instead of latest?

Posted: Fri Jul 31, 2009 6:22 am
by alaskalivedotnet
Thank you Qphoria for your very informative, exact informational post.

Your time and efforts are GREATLY appreciated.

Thank you again!!! ;D

Re: How to show "random" products on homepage instead of latest?

Posted: Mon Aug 03, 2009 8:41 pm
by yuwenlong126
thanks

Re: How to show "random" products on homepage instead of latest?

Posted: Tue Aug 04, 2009 10:41 am
by jblood
this is all well and good, but the randomized query gets cached (like all product queries), leaving the same results on the home page (which isn't very random).

you guys know an easy way around this?

Re: How to show "random" products on homepage instead of latest?

Posted: Tue Aug 04, 2009 10:46 am
by jblood
derp i'm stupid.

didn't see this line right below the query that you can simply comment out

Code: Select all

$this->cache->set('product.latest.' . $this->language->getId() . '.' . $limit, $product);

Re: How to show "random" products on homepage instead of latest?

Posted: Tue Sep 29, 2009 5:22 pm
by yegga
so i've commented out the cache line and changed the ORDER BY to rand() - and my products are still not randomised - what gives?

Re: How to show "random" products on homepage instead of latest?

Posted: Tue Sep 29, 2009 7:35 pm
by Qphoria
delete the cache files in the system/cache folder, then try

Re: How to show "random" products on homepage instead of latest?

Posted: Wed Oct 07, 2009 1:26 am
by topgiftsuk
Qphoria wrote:delete the cache files in the system/cache folder, then try
Hi, I opened system/cache and I can only see an index.html file, do I delete this whole file? or shall I delete the whole folder etc?

Sorry im new :P

Re: How to show "random" products on homepage instead of lat

Posted: Wed Dec 15, 2010 9:05 am
by KrawlOff-Road
How do I change this? I went to ftp.oursite.com and it wont let me change it?

-Jason

Re: How to show "random" products on homepage instead of lat

Posted: Wed Dec 15, 2010 9:23 am
by Qphoria
do not delete the folder..just the files inside system/cache

Re: How to show "random" products on homepage instead of lat

Posted: Thu Jan 05, 2012 11:50 pm
by xlam
Qphoria wrote:EDIT: catalog/model/catalog/product.php

FIND this function:

Code: Select all

public function getLatestProducts($limit) {
INSIDE THAT Function, FIND:

Code: Select all

ORDER BY p.date_added
REPLACE WITH:

Code: Select all

ORDER BY rand()
not work for me using OC 1.5.1.3 any idea?

Re: How to show "random" products on homepage instead of lat

Posted: Wed Jan 18, 2012 7:01 pm
by nulosep
and special products randon ???

OC 1.5.1.3 any idea?

Re: How to show "random" products on homepage instead of lat

Posted: Tue Jan 31, 2012 8:06 am
by nulosep
nulosep wrote:and special products randon ???

OC 1.5.1.3 any idea?

???

Re: How to show "random" products on homepage instead of lat

Posted: Sun Mar 18, 2012 6:52 am
by snisson
Seems that
public function getLatestProducts($limit)
is not used any more.

I found catalog/controller/module/latest.php

when you open it, around row 22 you should find:

$data = array(
'sort' => 'p.date_added',
'order' => 'DESC',
'start' => 0,
'limit' => $setting['limit']
);

and you should change it to

$data = array(
'sort' => 'RAND()',
'order' => '',
'start' => 0,
'limit' => $setting['limit']
);

that work perfect for me.

Re: How to show "random" products on homepage instead of lat

Posted: Sun Mar 18, 2012 7:14 am
by snisson
Also, to avoid cashing of random products list, I made another change in catalog/model/catalog/product.php

around line 35 in function

public function getProducts($data = array())

there is a line

$product_data = $this->cache->get('product.' . (int)$this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . (int)$customer_group_id . '.' . $cache);

I changed it with

if ($data['sort'] == 'RAND()') {
$product_data = array();
} else {
$product_data = $this->cache->get('product.' . (int)$this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . (int)$customer_group_id . '.' . $cache);
}

so, if order is random it will create empty array instead of reading product data from cache.