|

Redirect To Product Page If There Is Only One Product In Category
Posted 09 April 2014 - 12:10 PM #1
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
Posted 09 April 2014 - 12:32 PM #2
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
CS-Cart Development Services, Custom Design & Authorized Reseller
GET A FREE QUOTE
Posted 09 April 2014 - 01:04 PM #3
Works just as required. Brilliant.
Thank you.
kind regards
raff
Posted 09 April 2014 - 01:07 PM #4
---
Valentin
part of hungryweb.net
CS-Cart Development Services, Custom Design & Authorized Reseller
GET A FREE QUOTE
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
Posted 28 June 2017 - 06:54 AM #6
Thanks very much for posting this DVSGR! Helped us out a great deal.
Cheers,
SWiM.
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 1210 Multi-Vendor USD 1250 Multi-Vendor PLUS USD 3100 (2775)
CS-Cart Ultimate USD 4025 CS-Cart + YOUPI USD 1459 Multi-Vendor Ultimate USD 7500 (6000)
Posted 18 February 2019 - 06:37 PM #8
Hi Guys,
sorry to inform you that NONE of above solutions works.
1. Solution 1 (HungryWeb and Fotis) gives error SERVICE UNAVAILABLE
2. Solution 2 (eComLabs addon) is NOT solution, bec it only works if you search for it.
If you have it as a link in your menu, it will open Categorie instead of opening Product, even if you have only 1 product in that categorie.
Does anyone know working solution to open single product when customer click on category with single product?
Thanks
Erol
Posted 19 February 2019 - 05:25 AM #9
My changes add-on should be enabled for this to work
#file
app/addons/my_changes/controllers/frontend/categories.post.php
* if don not exist, please create, folder structure and php file
#content
<?php /* * © 2019 Hungryweb * * @website: www.hungryweb.net * @support: support@hungryweb.net * */ if ( !defined('BOOTSTRAP') ) { die('Access denied'); } use Tygh\Registry; if(!defined('AJAX_REQUEST') && $mode == 'view' && !empty($_REQUEST['category_id'])){ $products = Tygh::$app['view']->getTemplateVars('products'); if(!empty($products) && count($products)==1){ $products = reset($products); return array(CONTROLLER_STATUS_REDIRECT, "products.view?product_id=".$products['product_id']); } }
* Tested on 4.9.2
also you can choose other redirect header
// Controller return statuses define('CONTROLLER_STATUS_REDIRECT', 302); define('CONTROLLER_STATUS_OK', 200); define('CONTROLLER_STATUS_NO_PAGE', 404); define('CONTROLLER_STATUS_DENIED', 403); define('CONTROLLER_STATUS_DEMO', 401);
* to change the redirect header just change constant
change:
return array(CONTROLLER_STATUS_REDIRECT, "products.view...
to:
return array(CONTROLLER_STATUS_OK, "products.view...
Edited by Hungryweb, 21 February 2019 - 05:44 AM.
CS-Cart Development Services, Custom Design & Authorized Reseller
GET A FREE QUOTE
Posted 20 February 2019 - 09:37 PM #10
Dear Hungryweb,
thanks for help..
I would like to use option 2 REDIRECT "also you can choose other redirect header"
Still, I am not sure where to place those Controller statuses and how to implement that file in cs-cart..
What should I do with it?
Also, will that redirect be funkcional even in future updates of cs-cart.
Thanks
Erol
Posted 21 February 2019 - 05:46 AM #11
@Erol I edit the post and now you have all the details needed to make it work
Also, will that redirect be funkcional even in future updates of cs-cart.
I am not able to know what can come with 5.x version but should work just fine with future CS-Cart upgrades
CS-Cart Development Services, Custom Design & Authorized Reseller
GET A FREE QUOTE
Posted 21 February 2019 - 09:16 AM #12
Hi,
Thanks for update.
Still do not get it..
Where to change
* to change the redirect header just change constant ?
Where is that file on my server or on my cs-cart?
How to find file to change?
Thanks
Erol