Post by jarek » Wed May 14, 2008 2:49 am

Hi all!
This small change to /catalog/controller/home.php will display 6 random products instead of lates one. This is first release, will be updated soon, to provide additional features.

Code: Select all

if (!$customer->isLogged()) {

			$view->set('text_greeting', $language->get('text_greeting', $url->href('account_login'), $url->href('account_create')));

		} else {

			$view->set('text_greeting', $language->get('text_logged', $customer->getFirstName()));

		}

		// Select Random products by JT

		$allProducts = array ();
		$results = $database->getRows("SELECT product_id FROM product WHERE status='1'");
		foreach($results as $result)
			$allProducts[] = $result['product_id'];
		$numberOfProducts = count($allProducts)-1;
		$randomProducts = array();
		$numberOfRandomProducts = 0;
		$randomMax = min( $numberOfProducts, 6 );
		$randomList = "";
		while( $numberOfRandomProducts < $randomMax ) {
			$ptr = rand(0, $numberOfProducts );
			if( $allProducts[$ptr]>0 ) {
				$randomList .= $allProducts[$ptr];
				if( $numberOfRandomProducts < ($randomMax-1) )
					$randomList .= ",";
				$randomProducts[] = $allProducts[$ptr];
				$allProducts[$ptr] = 0;
				$numberOfRandomProducts++;
			}
		}
		// End Random products

 

		$view->set('text_latest', $language->get('text_latest'));



		$product_data = array();

		$results = $database->getRows("select * from product p left join product_description pd on (p.product_id = pd.product_id) left join image i on (p.image_id = i.image_id) where p.status = '1' and pd.language_id = '" . (int)$language->getId() . "' and p.date_available < now() and p.status = '1' and p.product_id in (".$randomList.")");

Working example: http://lumisklep.pl

I'll be happy to see your comments and ideas to improve it.

Newbie

Posts

Joined
Mon May 05, 2008 1:41 pm

Post by gabibv » Mon May 26, 2008 4:40 am

Great job i just inplemented in me site  ;D. Thank`s

www.audio-car.ro

Newbie

Posts

Joined
Tue Oct 09, 2007 4:50 am

Post by Telefax » Tue Jun 17, 2008 5:05 am

Hi, as standard I have JavaScript turned of and notice that you have a most excellent work-around for when people don't have javascript turned on and looks on one of your images. Please could you post the code for the Javascript workaround you use on: http://lumisklep.pl/

Its fantastic, just what my Opencart needs before going live!

New member

Posts

Joined
Sun Apr 06, 2008 4:47 pm

Post by jarek » Tue Jun 17, 2008 3:02 pm

Are you asking about "click to enlarge"  feature ?
I've removed thickbox preview, because it is very slow and dissallows viewing of big pictures. My code isn't perfect but I still have no time to clear it.
If you want to play with it, I can send you all code of my opencart installation.

Newbie

Posts

Joined
Mon May 05, 2008 1:41 pm

Post by Telefax » Tue Jun 17, 2008 3:19 pm

You are a GODSEND! Look at my post: http://forum.opencart.com/index.php/topic,1262.0.html - I am totally stuck, your homepage has the MAGIC answer!

Aye, looking for a way to REMOVE that Lightbox/thickbox/Evilbox/Biznizz killer (it has many names) and replace it with something like your sollution...

I would love the code, and if possibe (if you got time) please post the CODE and where to enter it as I have HARD TIME seeing your code if you send me the plain files... but if you post files, please post only files with the code in and "tell" aprox what the code looks like, then I can implement it in my own cart :)

OFC I'll post the credit for the code to your site/name when my site is live, we don't run same biz, so its fair'n'square anyways ;D

I am into bonds/papermoney/antiques and such sweet fluff :)

You can email me directly at phone@working.se too, but its good to post files here so others can use em too since MANY don't want to use Cursebox/Evilbox/Painboxmaker...

Thanks alot!!!!!

New member

Posts

Joined
Sun Apr 06, 2008 4:47 pm

Post by jarek » Wed Jun 18, 2008 2:26 pm

Hi!
Attached are modified and added files:

in catalog/controller/product.php you look for lines with JT in comments: you have to replace one line with another.
Other files you have to add and customize to you needs. You have to add also two lines to
language/controller/product.php:

$_['text_bigphoto'] = 'Some title for large photo';
$_['text_back'] = 'Some text for return button';

If you have any problems, ask!

Jarek
--
http://lumisklep.pl

Newbie

Posts

Joined
Mon May 05, 2008 1:41 pm

Post by Telefax » Wed Jun 18, 2008 4:00 pm

I can hardly wait to implement your workaround, must first register the last items on my 2nd pass, then backup .

I understand your must have very little time, but since you know how to make proper code it would not be wrong to ask.

Is it very hard to code in a plain Javascript image popup instead of Opencart's own Lightbox/thickbox prewiev? For some time ago I partially had everyting to work, but it failed on the part where my code needed the image size.

So, really... what the Javascript popup should do is that when a customer click on the image a new window popup with the HUGE image and has scrollbars if the image don't fit in the window.

Well, I ask becouse the question has not been answered by others more than in a wispers like its VERY hard to implement, and myself I just failed on the part where the javascript needed to get the image size.

Could be neat to have the Javascript popup for another planned cart (art material).

I'll post the URL's when the items are registered btw!  ;D

New member

Posts

Joined
Sun Apr 06, 2008 4:47 pm

Post by jarek » Thu Jun 19, 2008 5:25 am

This is the best performance killer.
Generally, rand() is very slow function. Your query calls rand() for each row in table. My query calls it 6 times.
Jarek
http://lumisklep.pl

Newbie

Posts

Joined
Mon May 05, 2008 1:41 pm

Post by bruce » Thu Jun 19, 2008 9:52 pm

Yes, both the previous approaches work great on small datasets. With a really large catalog selecting or ordering on rand with a limit is nasty and returning a huge catalog into arrays and randomising is similar. Magnify that by lots of users and...

Have a look here for another approach that gets the range that the random numbers must be generated within, gets one and selects the product. Repeat as required, check for duplicates.

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm
Who is online

Users browsing this forum: No registered users and 1 guest