Post by guisauer » Sun Jan 23, 2011 1:10 am

I'd like to know if there's a way to limit the amount of related products displayed on the page. So, even if "product A" has 20 related products, I only want 6 to be displayed on the page.

And, second, is it possible for OpenCart to pick those 6 products randomly? So, if I refresh the page, I'd get another random 6 related products?

Thanks!

New member

Posts

Joined
Sun Dec 06, 2009 7:51 am

Post by Chones » Sun Jan 23, 2011 10:51 pm

The MySQL query that gets the related products is in catalog/model/catalog/product.php under

Code: Select all

public function getProductRelated($product_id) {
You could try adding:

Code: Select all

ORDER BY RAND() LIMIT 6
at the end

http://scarletandjones.com/
http://sharpdressedman.co.uk/
http://coffincompany.co.uk/
http://horsesculptures.co.uk/
If I've helped you out, why not buy me a beer? http://craigmurray.me.uk


User avatar
Active Member

Posts

Joined
Wed Mar 24, 2010 9:07 pm
Location - London

Post by guisauer » Mon Jan 24, 2011 2:49 am

Chones, very cool! Thank you so much!!!

So, in catalog/model/catalog/product.php I found this:

Code: Select all

		$product_related_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'");
and replaced it with this:

Code: Select all

		$product_related_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "' ORDER BY RAND() LIMIT 6");
Now I only get 6 results on the related products section, and they're randomly selected!

New member

Posts

Joined
Sun Dec 06, 2009 7:51 am
Who is online

Users browsing this forum: No registered users and 33 guests