Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Redirect To Product Page If There Is Only One Product In Category Rate Topic   - - - - -

 
  • raff
  • Member
  • Members
  • Join Date: 23-Feb 12
  • 21 posts

Posted 09 April 2014 - 12:10 PM #1

As in title, does anyone know how to set automatic redirection to a product if there is only one product in given category?
Say customer clicks on the category link from main drop-down menu, but if there is only one product in that category, he/she is taken directly to product page.

TIA
raff

PS. Using version 4.1.3

 
  • Hungryweb
  • Senior Member
  • Authorized Reseller
  • Join Date: 10-Feb 12
  • 1191 posts

Posted 09 April 2014 - 12:32 PM #2

Hi @raff,
For this to work you need to have My changes add-on enabled

#add into file app/addons/my_changes/controllers/frontend/categories.post.php (if not exist, please create, folder structure and php file )

<?php
/***************************************************************************
*																		  *
*		   (c) 2014 HungryWeb.net | Support at yum@hungryweb.net		  *
*																		  *
***************************************************************************/
use Tygh\Registry;
if (!defined('BOOTSTRAP')) { die('Access denied'); }
if($mode == 'view'){
if (!defined('AJAX_REQUEST')) {
  //get page data
  $products = Registry::get('view')->getTemplateVars('products');
  if(empty($products[1]) && !empty($products[0])){
   return array(CONTROLLER_STATUS_REDIRECT, "products.view?product_id=".$products[0]['product_id']);
  }
}
 
}

I hope that helps,

---
Valentin
part of hungryweb.net

 
  • raff
  • Member
  • Members
  • Join Date: 23-Feb 12
  • 21 posts

Posted 09 April 2014 - 01:04 PM #3

Valentin, you a STAR!
Works just as required. Brilliant.
Thank you.

kind regards
raff

 
  • Hungryweb
  • Senior Member
  • Authorized Reseller
  • Join Date: 10-Feb 12
  • 1191 posts

Posted 09 April 2014 - 01:07 PM #4

Thank you and You are welcome

---
Valentin
part of hungryweb.net

 
  • dvsgr
  • Senior Member
  • Authorized Reseller
  • Join Date: 14-Apr 09
  • 1410 posts

Posted 29 August 2016 - 08:02 AM #5

HI Guys

 

an updated version I needed for 43x (in 438 tested)

<?php

use Tygh\Registry;

if (!defined('BOOTSTRAP')) { die('Access denied'); }

if($mode == 'view'){
	if (!defined('AJAX_REQUEST')) {
		$products = Registry::get('view')->getTemplateVars('products');
		if(count($products) == 1) {
			$product = array_shift($products);
			return array(CONTROLLER_STATUS_REDIRECT, "products.view?product_id=".$product['product_id']);
		}
	}
}​

Fotis


Fotis Kourmadas
Cs-Cart Development - Cs-Cart Authorized Reseller 

 

Posted 28 June 2017 - 06:54 AM #6

Thanks very much for posting this DVSGR! Helped us out a great deal.

Cheers,

SWiM.



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 17267 posts

Posted 02 March 2018 - 12:55 PM #7

not sure it still works, but thanks both of you guys! you guys are amazing, I will need to check this later, thanks!

 

Our free Search Improvements module has the single product redirect option


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.