Post by itrends » Fri Jul 24, 2009 5:02 am

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

Anyone? :)

Active Member

Posts

Joined
Tue Jul 14, 2009 7:54 pm

Post by itrends » Sat Jul 25, 2009 3:35 am

Anyone tonight? :)

Active Member

Posts

Joined
Tue Jul 14, 2009 7:54 pm

Post by Qphoria » Sat Jul 25, 2009 3:37 am

change the sql query for getLatestProducts to use order by rand

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by fivepix » Thu Jul 30, 2009 6:44 am

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!

Newbie

Posts

Joined
Wed Jun 17, 2009 7:03 am

Post by Qphoria » Thu Jul 30, 2009 8:27 am

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()

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by fivepix » Fri Jul 31, 2009 5:01 am

Qphoria Awesome! much appreciated Thanks!

Newbie

Posts

Joined
Wed Jun 17, 2009 7:03 am

Post by alaskalivedotnet » Fri Jul 31, 2009 6:22 am

Thank you Qphoria for your very informative, exact informational post.

Your time and efforts are GREATLY appreciated.

Thank you again!!! ;D

perl, php, java, java script, My SQL, html, ASP, Action Script, Web 2.0....
I am wondering if I have forgotten more than I have remembered? Or, did they change it?
http://www.alaskalive.net



Posts

Joined
Sun Jul 26, 2009 11:03 am

Post by yuwenlong126 » Mon Aug 03, 2009 8:41 pm

thanks

Newbie

Posts

Joined
Sat Jul 18, 2009 9:26 pm

Post by jblood » Tue Aug 04, 2009 10:41 am

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?

Newbie

Posts

Joined
Tue Aug 04, 2009 10:35 am

Post by jblood » Tue Aug 04, 2009 10:46 am

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);

Newbie

Posts

Joined
Tue Aug 04, 2009 10:35 am

Post by yegga » Tue Sep 29, 2009 5:22 pm

so i've commented out the cache line and changed the ORDER BY to rand() - and my products are still not randomised - what gives?

Active Member

Posts

Joined
Tue Sep 08, 2009 5:03 am

Post by Qphoria » Tue Sep 29, 2009 7:35 pm

delete the cache files in the system/cache folder, then try

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by topgiftsuk » Wed Oct 07, 2009 1:26 am

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

Newbie

Posts

Joined
Wed Oct 07, 2009 1:24 am

Post by KrawlOff-Road » Wed Dec 15, 2010 9:05 am

How do I change this? I went to ftp.oursite.com and it wont let me change it?

-Jason

New member

Posts

Joined
Sun Oct 24, 2010 10:15 am

Post by Qphoria » Wed Dec 15, 2010 9:23 am

do not delete the folder..just the files inside system/cache

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by xlam » Thu Jan 05, 2012 11:50 pm

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?

Baju Muslim Baju Pria Baju Anak Baju Korea Sparepart Printer Baju Muslim JNE Surabaya


New member

Posts

Joined
Sun Dec 25, 2011 2:58 pm

Post by nulosep » Wed Jan 18, 2012 7:01 pm

and special products randon ???

OC 1.5.1.3 any idea?

New member

Posts

Joined
Thu Dec 29, 2011 8:10 am

Post by nulosep » Tue Jan 31, 2012 8:06 am

nulosep wrote:and special products randon ???

OC 1.5.1.3 any idea?

???

New member

Posts

Joined
Thu Dec 29, 2011 8:10 am

Post by snisson » Sun Mar 18, 2012 6:52 am

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.

Newbie

Posts

Joined
Sun Mar 18, 2012 6:48 am

Post by snisson » Sun Mar 18, 2012 7:14 am

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.

Newbie

Posts

Joined
Sun Mar 18, 2012 6:48 am
Who is online

Users browsing this forum: No registered users and 28 guests