Page 1 of 1

Single Product Redirect for Category and Search

Posted: Tue Jun 05, 2018 6:59 pm
by webs_bd
version 3.0.2.0.

For previous versions of Opencart we found extensions or a code snippet to redirect a category or search to a single product result, should a category or search result only contain one product.
Does anyone know of a way to do this in Opencart 3.0.2.0. ?

Thanks

Re: Single Product Redirect for Category and Search

Posted: Tue Jun 05, 2018 8:37 pm
by DigitCart
Hi,
In these files:

Code: Select all

catalog\controller\product\search.php
catalog\controller\product\category.php
Find:

Code: Select all

$results = $this->model_catalog_product->getProducts($filter_data);
Add after:

Code: Select all

if (count($results) == 1) {
	reset($results);
	$this->response->redirect($this->url->link('product/product', 'product_id=' . key($results), true));
}
Please do not edit the core files, Use ocmod or vqmod instead.

Re: Single Product Redirect for Category and Search

Posted: Wed Jun 06, 2018 5:43 am
by webs_bd
Thank you very much.
Will give this a try.

Re: Single Product Redirect for Category and Search

Posted: Tue Feb 18, 2020 11:55 pm
by doogy2223
Has anyone had any luck with this.. I need this function but it is not working for me.

Re: Single Product Redirect for Category and Search

Posted: Wed Feb 19, 2020 3:01 am
by cyclops12
doogy2223 wrote:
Tue Feb 18, 2020 11:55 pm
Has anyone had any luck with this.. I need this function but it is not working for me.
Well the code posted by digitcart above works on default 3.0.2.0

Re: Single Product Redirect for Category and Search

Posted: Fri Jan 12, 2024 2:11 am
by M1ch831Gr8nt
Do you have a solution for opencart v4.0.2.3?

Re: Single Product Redirect for Category and Search

Posted: Tue Jan 23, 2024 2:01 pm
by AquaJeth5517
Did you have a fix for this issue? Skyward FBISD

Re: Single Product Redirect for Category and Search

Posted: Tue Jan 23, 2024 10:38 pm
by paulfeakins
If anyone is still looking for a solution and can't find an extension, you could pay a developer such as ourselves or post a job in the Commercial Support Forum.