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));
}

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.