Page 1 of 2

[1.4.7 or less MOD] - Show Random products on the Home Page

Posted: Thu Mar 25, 2010 8:42 am
by Qphoria
This method doesn't strain the database for searching rand(). Instead it pulls back more products and uses php's shuffle() function

1. EDIT: catalog/controller/module/latest.php (or featured.php)

2. FIND:

Code: Select all

$results = $this->model_catalog_product->getLatestProducts($this->config->get('latest_limit'));   
3. REPLACE WITH:

Code: Select all

$results = $this->model_catalog_product->getLatestProducts(10 * (int)$this->config->get('latest_limit'));
srand((float)microtime() * 1000000);
shuffle($results); 
$results = array_slice($results, 0, $this->config->get('latest_limit'));
   
That will multiply the limit by 10 returning 40 products if the limit is 4... and randomize them, then return only the amount of the limit. That should work well. You could always change the 10 to 100 for even more randomized results

That's it! You can leave the model file alone.

I've also created vQmods for randomizng latest, featured, special, and bestsellers here:
http://forum.opencart.com/viewtopic.php?f=131&t=32570

Re: [MOD] - Show Random products on the Home Page

Posted: Sat Jul 17, 2010 6:50 am
by Chrissy Poo
Thank You, works perfect with OpenCart 1.4.8b :)

Re: [MOD] - Show Random products on the Home Page

Posted: Fri Aug 13, 2010 3:55 pm
by peecha85
this was what I was looking for! thanks Qphoria

Re: [MOD] - Show Random products on the Home Page

Posted: Mon Aug 23, 2010 10:00 pm
by voca
Thanks for that Qphoria, used in opencart 1.4.8b as well.

Re: [MOD] - Show Random products on the Home Page

Posted: Mon Nov 29, 2010 12:06 am
by zalto
is there a way to show random products of subcategorys?
if i click the main category. then in category module is shows category heading and thumb/text to all subcategorys.
i want to replace that in category module. to show random productlistngs from all subcategorys to that main category.

please help me do this.

Re: [MOD] - Show Random products on the Home Page

Posted: Wed Dec 08, 2010 12:59 am
by Qphoria
zalto wrote:is there a way to show random products of subcategorys?
if i click the main category. then in category module is shows category heading and thumb/text to all subcategorys.
i want to replace that in category module. to show random productlistngs from all subcategorys to that main category.

please help me do this.
1. EDIT: catalog/model/catalog/product.php

2. FIND: getProductsByCategoryId

3. INSIDE THAT FUNCTION, IN THE MIDDLE FIND:

Code: Select all

$sql .= " ORDER BY p.sort_order";
4. REPLACE WITH:

Code: Select all

$sql .= " ORDER BY rand()";

Re: [MOD] - Show Random products on the Home Page

Posted: Wed Dec 08, 2010 2:42 am
by zalto
thanks.
i found that my site did to much loading. so i did another solution
i use a jquery category menu. and overrided the system to not load at all when i click the main topcategorymenu.
it only open the sub category listings in the categorymodule. and still showing the main home page. and then it loads the products from the subcategory only when i click the submenu..

Re: [MOD] - Show Random products on the Home Page

Posted: Wed Dec 08, 2010 3:37 am
by Lao
Qphoria wrote:There is a much better way I found using PHP instead of straining the database.
Niiice! ;)

Re: [MOD] - Show Random products on the Home Page

Posted: Fri Jan 07, 2011 3:35 am
by wandotshop
Qphoria wrote:Created vqmods for random latest, featured, bestsellers, and specials using the new no-strain method
sorry..i dont have any ideal what should i do after download your file...
could u tell me how to install it? or what?

Re: [MOD] - Show Random products on the Home Page

Posted: Fri Jan 07, 2011 4:04 am
by Qphoria
Get VirtualQMod from the link in my signature. That has all the info you need to know.

Re: [MOD] - Show Random products on the Home Page

Posted: Fri Jan 07, 2011 9:44 pm
by wandotshop
Success!!! :) TQ Qphoria...
anyway i just wonder...for Random Featured product.. may i know how to change to 8 item showing event that the Latest product i set to 12 item. .. but for now to set 8 item at featured product ..i need to set at latest product :( ... could u let featured product Independence? so that i can set it what ever number i want..TQ

Re: [MOD] - Show Random products on the Home Page

Posted: Fri Jan 07, 2011 10:54 pm
by Qphoria
wandotshop wrote:Success!!! :) TQ Qphoria...
anyway i just wonder...for Random Featured product.. may i know how to change to 8 item showing event that the Latest product i set to 12 item. .. but for now to set 8 item at featured product ..i need to set at latest product :( ... could u let featured product Independence? so that i can set it what ever number i want..TQ
Was that english? You set the limits in the module itself. Set featured to limit 8 and latest to limit 12

Re: [MOD] - Show Random products on the Home Page

Posted: Sat Jan 08, 2011 12:39 am
by wandotshop
Qphoria wrote:
wandotshop wrote:Success!!! :) TQ Qphoria...
anyway i just wonder...for Random Featured product.. may i know how to change to 8 item showing event that the Latest product i set to 12 item. .. but for now to set 8 item at featured product ..i need to set at latest product :( ... could u let featured product Independence? so that i can set it what ever number i want..TQ
Was that english? You set the limits in the module itself. Set featured to limit 8 and latest to limit 12
Broken english :D...
sorry.. anyway..i already set the featured to limit 8... and latest i put it as 12.. but the actual shown my feature follow limit of latest which is 12... for your info i used Random for Featured but not for Latest... Only Featured box is random :( ..
what the issue??

Re: [MOD] - Show Random products on the Home Page

Posted: Sat Jan 08, 2011 12:52 am
by wandotshop
Qphoria wrote:
wandotshop wrote:Success!!! :) TQ Qphoria...
anyway i just wonder...for Random Featured product.. may i know how to change to 8 item showing event that the Latest product i set to 12 item. .. but for now to set 8 item at featured product ..i need to set at latest product :( ... could u let featured product Independence? so that i can set it what ever number i want..TQ
Was that english? You set the limits in the module itself. Set featured to limit 8 and latest to limit 12
Anyway when i uninstall featured product..and install again... still happen...
but when i disable random featured at vqmod folder. It work Good.. with limit 8 already setting before.. but i need it Random... then enable that random..the issue it same..the product shown 12 as same as Latest :(.... its2 about the script of random for featured? plz check..anyway i am using 1.4.9.1 version... TQ for your help :)

Re: [MOD] - Show Random products on the Home Page

Posted: Sat Jan 08, 2011 1:31 am
by Qphoria
Not sure.. i have all 4 of these running on my site: http://theqdomain.com/ocstore

The featured limit is 4 and the latest is 12

Re: [MOD] - Show Random products on the Home Page

Posted: Sat Jan 08, 2011 1:50 am
by wandotshop
Qphoria wrote:Not sure.. i have all 4 of these running on my site: http://theqdomain.com/ocstore

The featured limit is 4 and the latest is 12
ermm... what happen? what setting?? i not put any limit.. let it blank..but the result still shown 12 item as sama as i set at latest limit :( ... hurmmmmmmmmmmmmmmmmmmmmmmm.....

for your info i not edit anything at any file name featured...its? just copy the file Random featured xml your create then let it running at vqmod..

its there anything i should edit first??

Re: [MOD] - Show Random products on the Home Page

Posted: Sat Jan 08, 2011 1:54 am
by Qphoria
When you enable the featured module there is a field for limit.. if you leave it empty I think it defaults to 10 in the code. Just enter 8

Re: [MOD] - Show Random products on the Home Page

Posted: Sun Jan 16, 2011 8:05 am
by atlee
Qphoria wonderful job with the VirtualQMod idea, modifying files then updating the version of OpenCart and having to remodify files all over again, this has just saved a lot of time, excellent work.

Re: [MOD] - Show Random products on the Home Page

Posted: Wed Jan 26, 2011 5:06 pm
by georget
I tried the no strain version without using vqmod and keep getting
Parse error: syntax error, unexpected T_VARIABLE in /wwwroot/catalog/controller/module/latest.php on line 17

Code: Select all

<?php
class ControllerModuleLatest extends Controller {
	protected function index() {
		$this->language->load('module/latest');

      	$this->data['heading_title'] = $this->language->get('heading_title');

		$this->load->model('catalog/product');
		$this->load->model('catalog/review');
		$this->load->model('tool/seo_url');
		$this->load->model('tool/image');

		$this->data['button_add_to_cart'] = $this->language->get('button_add_to_cart');

		$this->data['products'] = array();

		$results = $this->model_catalog_product->getLatestProducts(100 * (int)$this->config->get('latest_limit'));
			srand((float)microtime() * 1000000);
			shuffle($results); 
		$results = array_slice($results, 0, $this->config->get('latest_limit'));

		foreach ($results as $result) {
			if ($result['image']) {
				$image = $result['image'];
			} else {
				$image = 'no_image.jpg';
			}

			if ($this->config->get('config_review')) {
				$rating = $this->model_catalog_review->getAverageRating($result['product_id']);
			} else {
				$rating = false;
			}

			$special = FALSE;

			$discount = $this->model_catalog_product->getProductDiscount($result['product_id']);
Any idea what is causing this?

Re: [MOD] - Show Random products on the Home Page

Posted: Wed Jan 26, 2011 6:44 pm
by nbg4ever
you are the best human on this bloody world!!!
of course I meant Qphoria.