Post by Qphoria » Thu Mar 25, 2010 8:42 am

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

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Chrissy Poo » Sat Jul 17, 2010 6:50 am

Thank You, works perfect with OpenCart 1.4.8b :)

10% Discount on all Shared and Reseller Hosting Packages at Vidahost.com

Discount Code: DISCOUNT10


Active Member

Posts

Joined
Mon Jun 29, 2009 8:48 am
Location - UK

Post by peecha85 » Fri Aug 13, 2010 3:55 pm

this was what I was looking for! thanks Qphoria

Active Member

Posts

Joined
Tue May 11, 2010 10:28 pm

Post by voca » Mon Aug 23, 2010 10:00 pm

Thanks for that Qphoria, used in opencart 1.4.8b as well.

Active Member

Posts

Joined
Mon Aug 23, 2010 9:52 pm

Post by zalto » Mon Nov 29, 2010 12:06 am

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.

New member

Posts

Joined
Sun Nov 28, 2010 2:31 am

Post by Qphoria » Wed Dec 08, 2010 12:59 am

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

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by zalto » Wed Dec 08, 2010 2:42 am

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..

New member

Posts

Joined
Sun Nov 28, 2010 2:31 am

Post by Lao » Wed Dec 08, 2010 3:37 am

Qphoria wrote:There is a much better way I found using PHP instead of straining the database.
Niiice! ;)

I'm using Open Cart 1.5.4.1 on http://www.importpieseauto.ro


User avatar
Lao
Active Member

Posts

Joined
Tue Nov 23, 2010 3:31 pm
Location - Craiova, Romania

Post by wandotshop » Fri Jan 07, 2011 3:35 am

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?

New member

Posts

Joined
Wed Oct 06, 2010 12:15 am

Post by Qphoria » Fri Jan 07, 2011 4:04 am

Get VirtualQMod from the link in my signature. That has all the info you need to know.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by wandotshop » Fri Jan 07, 2011 9:44 pm

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

New member

Posts

Joined
Wed Oct 06, 2010 12:15 am

Post by Qphoria » Fri Jan 07, 2011 10:54 pm

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

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by wandotshop » Sat Jan 08, 2011 12:39 am

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??

New member

Posts

Joined
Wed Oct 06, 2010 12:15 am

Post by wandotshop » Sat Jan 08, 2011 12:52 am

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

New member

Posts

Joined
Wed Oct 06, 2010 12:15 am

Post by Qphoria » Sat Jan 08, 2011 1:31 am

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

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by wandotshop » Sat Jan 08, 2011 1:50 am

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??

New member

Posts

Joined
Wed Oct 06, 2010 12:15 am

Post by Qphoria » Sat Jan 08, 2011 1:54 am

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

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by atlee » Sun Jan 16, 2011 8:05 am

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.

Newbie

Posts

Joined
Tue Nov 23, 2010 7:59 pm

Post by georget » Wed Jan 26, 2011 5:06 pm

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?

Newbie

Posts

Joined
Fri Jan 14, 2011 7:30 pm

Post by nbg4ever » Wed Jan 26, 2011 6:44 pm

you are the best human on this bloody world!!!
of course I meant Qphoria.

www.gedzet.com


Newbie

Posts

Joined
Fri Nov 26, 2010 5:19 pm
Who is online

Users browsing this forum: No registered users and 2 guests