Post by temptious » Wed Feb 29, 2012 7:33 pm

Is there a way to limit the number of related products on the products page?

I have a product that I want as an up-sell, it's related to around 50% of the products in my store.

However when you visit it's page half of my store is listed in it's related products tab.

I have tried to remove some products from the links panel in Admin, but this removes it from both product pages on the store front.

Is there a simple way to limit these to 8 or even 4 products?

EDIT: OC 1.5 BTW

Newbie

Posts

Joined
Fri Feb 10, 2012 8:02 pm

Post by uksitebuilder » Wed Feb 29, 2012 11:21 pm

edit: catalog/model/catalog/product.php

find (around line 377)

Code: Select all

	public function getProductRelated($product_id) {
		$product_data = array();

		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related pr LEFT JOIN " . DB_PREFIX . "product p ON (pr.related_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pr.product_id = '" . (int)$product_id . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");
		
		foreach ($query->rows as $result) { 
			$product_data[$result['related_id']] = $this->getProduct($result['related_id']);
		}
		
		return $product_data;
	}
change to

Code: Select all

	public function getProductRelated($product_id) {
		$product_data = array();

		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related pr LEFT JOIN " . DB_PREFIX . "product p ON (pr.related_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pr.product_id = '" . (int)$product_id . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' LIMIT 0, 8");
		
		foreach ($query->rows as $result) { 
			$product_data[$result['related_id']] = $this->getProduct($result['related_id']);
		}
		
		return $product_data;
	}
All I did was add LIMIT 0,8 to the SQL which will only grab up to 8 results.

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by temptious » Wed Feb 29, 2012 11:26 pm

Thanks mate! I'll give that a go.

Newbie

Posts

Joined
Fri Feb 10, 2012 8:02 pm

Post by Johnathan » Thu Mar 01, 2012 1:25 am

A slightly less complicated edit (limiting it to a random selection of 5):

Code: Select all

IN:
/catalog/controller/module/featured.php

BEFORE:
foreach ($products as $product_id) {

ADD:
shuffle($products);
$products = array_slice($products, 0, 5); 

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by temptious » Thu Mar 01, 2012 6:50 am

Thanks both but I've tried both ways but nothing has changed?

Still getting all related products in the tab.

Any ideas?

Newbie

Posts

Joined
Fri Feb 10, 2012 8:02 pm

Post by Johnathan » Thu Mar 01, 2012 11:48 am

Sorry, I misread your post title...I thought it said Featured Products. (I blame it on the lack of sleep.) Try this:

Code: Select all

IN:
/catalog/controller/product/product.php

AFTER:
$results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);

ADD:
shuffle($results);
$results = array_slice($results, 0, 5); 

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by temptious » Thu Mar 01, 2012 5:57 pm

Johnathan wrote:Sorry, I misread your post title...I thought it said Featured Products. (I blame it on the lack of sleep.) Try this:

Code: Select all

IN:
/catalog/controller/product/product.php

AFTER:
$results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);

ADD:
shuffle($results);
$results = array_slice($results, 0, 5);  
Result! Thanks very much Jonathan.

Now get some sleep!

Newbie

Posts

Joined
Fri Feb 10, 2012 8:02 pm

Post by Johnathan » Thu Mar 01, 2012 9:39 pm

Glad it worked! I'll work on getting some sleep, but my 6-week old daughter decided she will only sleep while being held, which is making it tough. :)

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by Nooneknowsall » Fri Mar 09, 2012 1:45 pm

uksitebuilder wrote:edit: catalog/model/catalog/product.php

find (around line 377)

Code: Select all

	public function getProductRelated($product_id) {
		$product_data = array();

		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related pr LEFT JOIN " . DB_PREFIX . "product p ON (pr.related_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pr.product_id = '" . (int)$product_id . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");
		
		foreach ($query->rows as $result) { 
			$product_data[$result['related_id']] = $this->getProduct($result['related_id']);
		}
		
		return $product_data;
	}
change to

Code: Select all

	public function getProductRelated($product_id) {
		$product_data = array();

		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related pr LEFT JOIN " . DB_PREFIX . "product p ON (pr.related_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pr.product_id = '" . (int)$product_id . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' LIMIT 0, 8");
		
		foreach ($query->rows as $result) { 
			$product_data[$result['related_id']] = $this->getProduct($result['related_id']);
		}
		
		return $product_data;
	}
All I did was add LIMIT 0,8 to the SQL which will only grab up to 8 results.
Hello, Thanks for this hint. I limited the related products to 8. But, I will also like the related products to be randomized. Can you help me?

Newbie

Posts

Joined
Sat Feb 25, 2012 5:10 am

Post by dydyt » Thu Oct 25, 2012 3:22 am

does not work for me

Newbie

Posts

Joined
Wed Oct 17, 2012 3:28 am

Post by MikeSCC » Thu Nov 22, 2012 6:31 pm

Johnathan wrote:Sorry, I misread your post title...I thought it said Featured Products. (I blame it on the lack of sleep.) Try this:

Code: Select all

IN:
/catalog/controller/product/product.php

AFTER:
$results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);

ADD:
shuffle($results);
$results = array_slice($results, 0, 5); 
Thank you very much for this.

Active Member

Posts

Joined
Tue Nov 20, 2012 5:55 pm

Post by Timmy564 » Wed Jun 12, 2013 11:31 pm

Johnathan wrote:Sorry, I misread your post title...I thought it said Featured Products. (I blame it on the lack of sleep.) Try this:

Code: Select all

IN:
/catalog/controller/product/product.php

AFTER:
$results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);

ADD:
shuffle($results);
$results = array_slice($results, 0, 5);
Your post is over 1 year old but still helpful. I have just tried this with 1.5.5.1 and seem to be working perfectly, thank you. :)

Image

Occasional Furniture | Dining Sets | Bedroom
Sofas | Chandeliers | Vases


Newbie

Posts

Joined
Mon May 20, 2013 6:18 am


Post by seshalyn » Mon Jul 08, 2013 2:12 pm

Timmy564 wrote:
Johnathan wrote:Sorry, I misread your post title...I thought it said Featured Products. (I blame it on the lack of sleep.) Try this:

Code: Select all

IN:
/catalog/controller/product/product.php

AFTER:
$results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);

ADD:
shuffle($results);
$results = array_slice($results, 0, 5);
Your post is over 1 year old but still helpful. I have just tried this with 1.5.5.1 and seem to be working perfectly, thank you. :)
:laugh: <- My reaction when I try something and it works with the first attempt! Also worked for me today using 1.5.4
Thanks Jonathan!

I <3 Opencart, but I HATE PHP!


User avatar
Newbie

Posts

Joined
Fri Jul 13, 2012 3:49 pm


Post by drbyte » Sun May 25, 2014 5:23 pm

A safer one

Drop below code into a new file call it limit_number_of_related_products.xml then drop it in to your VQMOD folder

you can name it whatever you want

Code: Select all

<modification>
	<id>Limit Number Of Related Products</id>
	<version>2.0</version>
	<author>Sam</author>
	<file name="catalog/controller/product/product.php">
		<operation>
			<search position="after"><![CDATA[$results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);]]></search>
			<add><![CDATA[shuffle($results); $results = array_slice($results, 0, 6);]]></add>
		</operation>
	</file>
</modification>
Change the number form 6 to whatever you want

Delete vq2-catalog_controller_product_product.php from your vqcache and you are ready to do

New member

Posts

Joined
Sun Jan 01, 2012 7:20 pm

Post by draysniro » Tue May 27, 2014 5:39 pm

drbyte wrote:A safer one

Drop below code into a new file call it limit_number_of_related_products.xml then drop it in to your VQMOD folder

you can name it whatever you want

Code: Select all

<modification>
	<id>Limit Number Of Related Products</id>
	<version>2.0</version>
	<author>Sam</author>
	<file name="catalog/controller/product/product.php">
		<operation>
			<search position="after"><![CDATA[$results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);]]></search>
			<add><![CDATA[shuffle($results); $results = array_slice($results, 0, 6);]]></add>
		</operation>
	</file>
</modification>
Change the number form 6 to whatever you want

Delete vq2-catalog_controller_product_product.php from your vqcache and you are ready to do
Thank you for this! It's exactly what I was looking for!

Newbie

Posts

Joined
Fri Oct 26, 2012 7:03 am

Post by sohoz » Sun Jun 07, 2015 1:47 am

My vqcache files are follows,
I didn't find the vq2-catalog_controller_product_product.php, would you please tell me is there any file which one I'm looking for to delete ?

Attachments

vq.jpg

vqcache files - vq.jpg (92.6 KiB) Viewed 4818 times


Newbie

Posts

Joined
Fri Jun 05, 2015 6:41 pm
Who is online

Users browsing this forum: No registered users and 135 guests