Zen Cart Logo
Forums / General Questions / Redirecting a subcategory to an external site

Redirecting a subcategory to an external site

Views: 4,188

Results 21 to 40 of 43
16 May 2011, 12:02 AM
#21
drbyte avatar

drbyte

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 like

define('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

16 May 2011, 12:24 AM
#22
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Redirecting a subcategory to an external site

Nice! Avoids the need to change the destination of the category menu link at all, just intercepting the processing as the regular destination subcat page is about to open and going off to the external site instead.

17 May 2011, 2:52 PM
#23
dscarms avatar

dscarms

New Zenner

Join Date:
May 2010
Posts:
29
Plugin Contributions:
0

Re: Redirecting a subcategory to an external site

Thanks to you both - (Dr Byte and Black belt) as well as everyone else who contributed to this. I will try the code where specified and report back to you. I would be more than happy to make a contribution/donation if this works.
David

17 May 2011, 4:32 PM
#24
dscarms avatar

dscarms

New Zenner

Join Date:
May 2010
Posts:
29
Plugin Contributions:
0

Re: Redirecting a subcategory to an external site

Hi DrByte - Here are the results - created and installed the files as you directed in the earlier post #21. The site will no longer come up and displays - HTTP 500 Internal server error. The website cannot display the page
HTTP 500
Most likely causes:
•The website is under maintenance.
•The website has a programming error.

What you can try:
Refresh the page.

 Go back to the previous page. 

 More information

I noticed that the version the program code was written for was v1.3.9 and I am using v1.3.8. Would that have something to do with the error? I put in a modified section A on Post#21 with a specified category path 11 subcategory 52 and the destination URL and then installed it. File installed is as follows: external_category_links.php```

<?php define('FIREARMS_LINK_11_51', ‘[url]http://www6.davidsonsinc.com/consumers/subsites/inven_sql.asp?preview=&manufact_combo=Armscor&category_combo=None&price_range=None&mod_ser_combo=None&g_type=Semi-Automatic+Pistol&finish_type=None&calib_combo=None&sight_class_combo=None&num_rec=50&instock=all&offset_rec=0&b1.x=56&b1.y=14');[/url] //for cPath=11_51 define('FIREARMS_LINK_11_52', 'http://www6.davidsonsinc.com/consumers/subsites/inven_sql.asp?preview=&manufact_combo=Armscor&category_combo=None&price_range=None&mod_ser_combo=None&g_type=Shotgun&finish_type=None&calib_combo=None&sight_class_combo=None&num_rec=50&instock=all&offset_rec=0&b1.x=67&b1.y=10'); //for cPath=11_52 define('FIREARMS_LINK_32_57', 'http://www.yourothersite.com/whatever_page_url'); //for cPath=32_57 define('FIREARMS_LINK_32_57', 'http://www.yourothersite.com/whatever_page_url'); //for cPath=32_57 ``` The 500 Internal server error popped up. So I replaced it with the basic code in Section A and the 500 Internal server error continued to pop up. Any ideas as to the bug and the fix? Thanks for all the help!!!! David
17 May 2011, 4:35 PM
#25
dscarms avatar

dscarms

New Zenner

Join Date:
May 2010
Posts:
29
Plugin Contributions:
0

Re: Redirecting a subcategory to an external site

Part of the file was cut off - here is the file:
external_category_links.php```php

<?php define('FIREARMS_LINK_11_51', ‘http://www6.davidsonsinc.com/consumers/subsites/inven_sql.asp?preview=&manufact_combo=Armscor&category_combo=None&price_range=None&mod_ser_combo=None&g_type=Semi-Automatic+Pistol&finish_type=None&calib_combo=None&sight_class_combo=None&num_rec=50&instock=all&offset_rec=0&b1.x=56&b1.y=14'); //for cPath=11_51 define('FIREARMS_LINK_11_52', 'http://www6.davidsonsinc.com/consumers/subsites/inven_sql.asp?preview=&manufact_combo=Armscor&category_combo=None&price_range=None&mod_ser_combo=None&g_type=Shotgun&finish_type=None&calib_combo=None&sight_class_combo=None&num_rec=50&instock=all&offset_rec=0&b1.x=67&b1.y=10'); //for cPath=11_52 define('FIREARMS_LINK_32_57', 'http://www.yourothersite.com/whatever_page_url'); //for cPath=32_57 define('FIREARMS_LINK_32_57', 'http://www.yourothersite.com/whatever_page_url'); //for cPath=32_57 define('FIREARMS_LINK_32_57', 'http://www.yourothersite.com/whatever_page_url'); //for cPath=32_57 ```
17 May 2011, 4:46 PM
#26
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Redirecting a subcategory to an external site

Do you really have 'FIREARMS_LINK_32_57' defined three times? That would cause a PHP error, as you cannot redefine a constant.
If you are saving those lines for future modification, comment them out for now.

18 May 2011, 6:57 AM
#27
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Redirecting a subcategory to an external site

Er, um, the first apostrophe you entered before the http URL is a back-quote, not a proper apostrophe like it should be.

18 May 2011, 2:39 PM
#28
dscarms avatar

dscarms

New Zenner

Join Date:
May 2010
Posts:
29
Plugin Contributions:
0

Re: Redirecting a subcategory to an external site

Hi Black belt - It was being saved for future use and as a sample of the attempt that I made to install the files to see if the modification would work. After some reflection - I realized that may have contributed to the error message and I will edit them out. I presume if I add or delete any more categories or subcategories under the "firearms" main category, I will have to add or delete the php file contents. I further presume that this re-direct would also work for just a sub-category within a category - or am I incorrect?
Hi DrByte- Thanks - The problem usually lies in the details - thanks for pointing it out for me. I will try it again and follow back up with the details.
Thanks again,
David

18 May 2011, 3:16 PM
#29
dscarms avatar

dscarms

New Zenner

Join Date:
May 2010
Posts:
29
Plugin Contributions:
0

Re: Redirecting a subcategory to an external site

Well Guys - Not having the error 500 Internal server error pop up. I changed the apostrophe to the proper one mentioned post 27 and just made the php file to two lines to test it.

And it is a no go. It will not redirect from the dscgunstore.com site. To test it, I am on the dscgunstore.com site, then to Firearms category, then to Armscor subcategory, then to Handgun subcat, then to pistol subcat which show the url as http://dscgunstore.com/index.php?main_page=index&cPath=2_11_51 and then the other test is Firearms category, then to Armscor subcategory, then to shotgun subcat which shows the url as http://dscgunstore.com/index.php?main_page=index&cPath=2_11_52
I am presuming the simple fix would be to expand the specific path in the php code of section A but I wanted to run it past you guys. Maybe there is something else that maybe causing it.

Here's what I have on the server:

Section A. /includes/extra_datafiles/external_category_links.php - as follows:

<?php define('FIREARMS_LINK_11_51', 'http://www6.davidsonsinc.com/consumers/subsites/inven_sql.asp?preview=&manufact_combo=Armscor&category_combo=None&price_range=None&mod_ser_combo=None&g_type=Semi-Automatic+Pistol&finish_type=None&calib_combo=None&sight_class_combo=None&num_rec=50&instock=all&offset_rec=0&b1.x=56&b1.y=14'); //for cPath=11_51 define('FIREARMS_LINK_11_52', 'http://www6.davidsonsinc.com/consumers/subsites/inven_sql.asp?preview=&manufact_combo=Armscor&category_combo=None&price_range=None&mod_ser_combo=None&g_type=Shotgun&finish_type=None&calib_combo=None&sight_class_combo=None&num_rec=50&instock=all&offset_rec=0&b1.x=67&b1.y=10'); //for cPath=11_52 I am thankful for all your help especially being this close to solving it. Thanks, David
18 May 2011, 3:55 PM
#30
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Redirecting a subcategory to an external site

If the actual cPath is 2_11_52, then FIREARMS_LINK_11_52 will never work. DrByte's code will work for just the subcategory id
FIREARMS_LINK_52
or the whole cPath
FIREARMS_LINK_2_11_52.

19 May 2011, 2:21 PM
#31
dscarms avatar

dscarms

New Zenner

Join Date:
May 2010
Posts:
29
Plugin Contributions:
0

Re: Redirecting a subcategory to an external site

Thanks Black Belt - I suspected that but wanted to confirm it before complicating it any further. I will make the change to the cpath and will let you know the results.
Thanks again to you and DrByte.
David

20 May 2011, 2:14 PM
#32
dscarms avatar

dscarms

New Zenner

Join Date:
May 2010
Posts:
29
Plugin Contributions:
0

Re: Redirecting a subcategory to an external site

Well Black Belt (and Dr Byte) the re-direct still does not work from the categories or subcategories with either the full cPath number or just the Subcategory cPath number. I have changed the cPath number several different ways with no re-direct. On the dscgunstore site (when it should re-direct to the davisons site) it states "there are no products in this category" and will not re-direct to my other store at davidsons curl. I have not changed anything else that is listed in post #29. Any additional ideas? Is it a template issue or program constant issue that has to have a product entered in the dscgunstore site preventing the re-direct? Could a redirect be done from the product entry template if a product has to be entered? Thanks for all the help and assistance so far.
David

25 May 2011, 6:27 AM
#33
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Redirecting a subcategory to an external site

Oops ... I just tested it, and I know why it's not working:

Back in post #21 I wrote:> c) create a new file: /includes/auto_loaders/config_external_category_links.php
But that should have been "config.external_category_links.php" ... note the "." instead of "_" :blush:

And I also made some typos in the PHP code I had put in part (b) of post #21.
I've edited that code to fix those typos. Please replace the content of that observer file.

Sorry ... I should have tested it, but I was swamped at the time I posted it.

25 May 2011, 5:48 PM
#34
dscarms avatar

dscarms

New Zenner

Join Date:
May 2010
Posts:
29
Plugin Contributions:
0

Re: Redirecting a subcategory to an external site

Hi DrByte - Thanks for the help - you have been super in being able to accomplish it anyway - so i am in no way complaining.

I made the correction to part C and but I am guessing at the typo(s) correction you are referring to in part B of #21 and where exactly you have edited the php code in that observer file. Would it be possible for you post the corrected file of part B of #21 so i can be sure that the corrections to the typos are what I suspect need to be changed.

Again I deeply Appreciate all your help and assistance and plan to make a donation as soon as this works.
David

25 May 2011, 6:18 PM
#35
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Redirecting a subcategory to an external site

Just replace the entire file content - don't mess around trying to substitute bits. DrByte edited that post so it is now correct.

26 May 2011, 3:56 PM
#36
dscarms avatar

dscarms

New Zenner

Join Date:
May 2010
Posts:
29
Plugin Contributions:
0

Re: Redirecting a subcategory to an external site

Hi Black belt and DrByte - I am not getting it - it is not working and I am clearly missing something to get it to work especially if Dr Byte has tested it and it works for him.

I have recopied the entire file from #21 part B ( and then tried just changing the two lines in part B that Black belt suggested) and it did not work with the entire cpath for two test "products". The test pathway is for Firearms -2, Armscor -11, Handguns - 51, pistols - 54. AND the other cpath is firearms - 2, armscor - 11, shotguns -52. It does not redirect and states that there is "no product in this category".

I realize you both are busy and have spent a fair amount of time with this issue. I do appreciate your efforts and assistance. Thanks for all your help - I am certain that this can be resolved.
David

26 May 2011, 6:57 PM
#37
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Redirecting a subcategory to an external site

Found it. The problem is that the code I gave you was written for v1.3.9, but you're using v1.3.8a.

Here's the adjustment required -- note the file in step "b", and change the code as shown from this:function external_category_links() { [B]$this[/B]->attach($this, array('NOTIFY_HEADER_START_INDEX')); }to this:```
function external_category_links() {
[B]global $zco_notifier;
$zco_notifier[/B]
->attach($this, array('NOTIFY_HEADER_START_INDEX'));
}

26 May 2011, 7:12 PM
#38
dscarms avatar

dscarms

New Zenner

Join Date:
May 2010
Posts:
29
Plugin Contributions:
0

Re: Redirecting a subcategory to an external site

DrByte - It works great and is absolutely outstanding. The technical support that you provided was above and beyond what I ever expected and would have imagined. You certainly over-delivered on what I hoped to accomplish. Kudos to you and your support. Have a super day!!! Donation is on its way!!

26 May 2011, 8:05 PM
#39
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Redirecting a subcategory to an external site

David,
I'm glad we were able to get a solution for you.
And thanks for the donation to Zen Cart.
Cheers

7 Jun 2011, 3:15 PM
#40
dscarms avatar

dscarms

New Zenner

Join Date:
May 2010
Posts:
29
Plugin Contributions:
0

Re: Redirecting a subcategory to an external site

Dr Byte,
I was glad to make the donation and get the solution. I am sure others will be able to use it as well. Although - there is a new twist to the re-direct that popped up when I was testing it. The re-direct itself works great - The Problem is the destination curl needs a cookie from my webstore at the Davidsons site to get my pricing and the live inventory. I did not realize this earlier because the Davidsons tech person neglected to tell me that bit of info. The destination url database that I built, will work as long as the Davidsons site cookie is present on the individual customers computer from being at my store on the Davidsons site.

I have the Davidsons tech people looking into making the correction to the destination url so it can go through - but no response or luck - So far. So my question is - Is it possible to have my Davidsons webstore cookie or session-cookie installed on my dscgunstore site at the Firearms category or at the individual subcategories so when the customer goes to the Firearms category or at the individual subcategories the re-direct will be fully complete? Any ideas/suggestions?

Thanks for all your help and assistance,
David