Sensei
- Join Date:
- Jan 2004
- Posts:
- 63,513
- Plugin Contributions:
- 177
Redirecting a subcategory to an external site
gjh42:
Just thinking about a simplified way of making the corresponding links...
you could define a constant for each subcat likedefine('FIREARMS_LINK_32_57', 'http://www.yourothersite.com/whatever_page'); //for cPath=32_57
then in the category listing, see if there is a constant that matches the cPath and use its defined value instead of the regular link.
Jumping from Glenn's suggestion, try this:
a) create a new file: /includes/extra_datafiles/external_category_links.php containing this:```
<?php define('FIREARMS_LINK_32_57', 'http://www.yourothersite.com/whatever_page_url'); //for cPath=32_57 ``` b) create a new file: /includes/classes/observers/class.external_category_links.php containing this PHP code:``` <?php /** * @package addons * @copyright Copyright 2003-2011 Zen Cart Development Team * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 * @version $Id: class.external_category_links.php 2011-05-15 17:24:00Z drbyte $ * * Designed for v1.3.9h */ class external_category_links extends base { /** constructor method * * Attaches observer class to the global $zco_notifier and watch for a single notifier event. */ function external_category_links() { $this->attach($this, array('NOTIFY_HEADER_START_INDEX')); } /** Actual Method that does the desired activity * * Called by observed class when any of the notifiable events occur * * @param object $class * @param string $eventID */ function update(&$class, $eventID, $paramsArray = array()) { global $cPath, $current_category_id; if (defined('FIREARMS_LINK_' . $cPath) && substr(constant('FIREARMS_LINK_' . $cPath), 0, 4) == 'http') zen_redirect(constant('FIREARMS_LINK_' . $cPath)); if (defined('FIREARMS_LINK_' . $current_category_id) && substr(constant('FIREARMS_LINK_' . $current_category_id), 0, 4) == 'http') zen_redirect(constant('FIREARMS_LINK_' . $current_category_id)); } } ``` c) create a new file: /includes/auto_loaders/config.external_category_links.php with the following:``` <?php /** * Autoloader to instantiate observer class */ $autoLoadConfig[90][] = array('autoType'=>'class', 'loadFile'=>'observers/class.external_category_links.php'); $autoLoadConfig[90][] = array('autoType'=>'classInstantiate', 'className'=>'external_category_links', 'objectName'=>'external_category_links'); ``` Then simply edit the file in step (a) as needed to add additional categories and their respective URLs, as per the pattern. Tip: You can either use the complete cPath such as 32_57 or just 57 if it doesn't really matter what the full complete cat-subcat-subcat-subcat path is. Also, just in case you're wondering about the missing ?> at the end of those code snippets, see here: <https://www.zen-cart.com/tutorials/index.php?article=313>While I confess I've not tested this directly, I'm sure if there's a bug in it we can fix it simply.
If this works for you, donations are always appreciated at: https://www.zen-cart.com/donate