Zen Cart Logo
Forums / General Questions / Redirect discontinued items

Redirect discontinued items

Views: 4,919

Results 1 to 20 of 34
24 Dec 2013, 7:36 PM
#1
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Redirect discontinued items

How do redirect discontinued items/products to a the domain index page? Or to make it display the products main category?

24 Dec 2013, 11:52 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Redirect discontinued items

Kevin205:

How do redirect discontinued items/products to a the domain index page? Or to make it display the products main category?

I haven't gone through all the necessary (potentially necessary) settings, but in the admin panel, configuration, my store, missing page check. If you set it to on, then pages that do not exist will redirect to the main page.

I thought there was something/somewhere else to also check, but that should get you started.

26 Dec 2013, 5:49 PM
#3
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Redirect discontinued items

mc12345678:

I haven't gone through all the necessary (potentially necessary) settings, but in the admin panel, configuration, my store, missing page check. If you set it to on, then pages that do not exist will redirect to the main page.

I thought there was something/somewhere else to also check, but that should get you started.

Thanks for the reply.

I never knew that option existed!

For testing purposes when I set the Products Status: to Out of Stock, regardless of what I choose, On, Off or Page Not Found option from Admin>Configuration>My Store
Default=On
On = Send missing pages to 'index'
Off = Don't check for missing pages
Page Not Found = display the Page-Not-Found page

It displays the Home>Category>Sub-Category breadcrumb navigation, up to the sub-category where the product was.
and it displays the following right after the breadcrumb (on the next line)
Sorry, the product was not found.

Any ideas why it's not being re-directed to the index page?

26 Dec 2013, 6:04 PM
#4
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Location:
Lansing, Michigan USA
Posts:
19,793
Plugin Contributions:
2

Re: Redirect discontinued items

I'm not sure if it's exactly your problem, but I don't believe that setting the product status to Out Of Stock (or setting the product quantity to 0) removes the remaining products from stock. I think the only way to remove the last one of a product from inventory is to have it go through the checkout process.

26 Dec 2013, 6:13 PM
#5
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: Redirect discontinued items

You're merging two separate code issues here

1 - missing 'pages'

2 - missing 'products'

What you want is to return to the index when the product query fails to return a product. It is NOT failing to return a page.

Here's what is happening when the message 'Sorry, the product was not found.' displays:

includes/modules/pages/product_info/main_template_vars.php
will run this code:
if ( $res->fields['total'] < 1 ) {

$tpl_page_body = '/tpl_product_info_noproduct.php';

} else {

$tpl_page_body = '/tpl_product_info_display.php';

which then publishes this page:
includes/templates/YOUR_TEMPLATE/templates/tpl_product_info_noproduct.php

with the message on it.

Change the noproduct page to the index page for each of your product types if applicable.

26 Dec 2013, 6:25 PM
#6
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Redirect discontinued items

stevesh:

I'm not sure if it's exactly your problem, but I don't believe that setting the product status to Out Of Stock (or setting the product quantity to 0) removes the remaining products from stock. I think the only way to remove the last one of a product from inventory is to have it go through the checkout process.

Hi Steve, you are correct.

I manually set the **Quantity **to 0 and Products Status: to Out of Stock.

It still displays as explained in post#3

Going and manually checkout products, one at a time?:no:

Is there another solution for this? To redirect discontinued products to the index?

26 Dec 2013, 7:16 PM
#7
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Location:
Lansing, Michigan USA
Posts:
19,793
Plugin Contributions:
2

Re: Redirect discontinued items

The easy way would be to do it in the database, but I'm not SQL expert enough to write the patch. I suspect twitchtoo is.

26 Dec 2013, 7:29 PM
#8
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Redirect discontinued items

twitchtoo:

You're merging two separate code issues here

1 - missing 'pages'

2 - missing 'products'

What you want is to return to the index when the product query fails to return a product. It is NOT failing to return a page.

Here's what is happening when the message 'Sorry, the product was not found.' displays:

includes/modules/pages/product_info/main_template_vars.php
will run this code:
if ( $res->fields['total'] < 1 ) {

$tpl_page_body = '/tpl_product_info_noproduct.php';

} else {

$tpl_page_body = '/tpl_product_info_display.php';

which then publishes this page:
includes/templates/YOUR_TEMPLATE/templates/tpl_product_info_noproduct.php

with the message on it.

Change the noproduct page to the index page for each of your product types if applicable.

Thank you twitchtoo for the reply,

I tried your solution, replacing tpl_product_info_noproduct.php with the following files:
includes/templates/MyTemplate/templates/tpl_index_default.php
Stopped displaying page info, including navigation breadcrumbs. Showing a blank center page. With the following error:

[26-Dec-2013 11:04:23 America] PHP Warning: require(): Filename cannot be empty in /public_html/includes/templates/MyTemplate/templates/tpl_index_default.php on line 40
[26-Dec-2013 11:04:23 America] PHP Fatal error: require(): Failed opening required '' (include_path='.:/usr/php/54/usr/lib64:/usr/php/54/usr/share/pear') in /public_html/includes/templates/MyTemplate/templates/tpl_index_default.php on line 400

includes/templates/MyTemplate/templates/tpl_index_product_list.php
Displays the following warning after the nav breadcrumbs:
WARNING: An Error occurred, please refresh the page and try again.
Stopped displaying the rest of the page. Showing a blank center page. With the following error:

[26-Dec-2013 11:02:16 America] PHP Fatal error: 1065:Query was empty :: in /public_html/includes/classes/db/mysql/query_factory.php on line 120

includes/templates/MyTemplate/templates/tpl_index_categories.php
Replacing the above file works :D, displaying the navigation breadcrumbs and sub-category name only, plus all other page information, all the the way down to the footer.

But when I change the URI to
http: // Domain.com /index.php?main_page=product_info&cPath=2_5&products_id=320132, id= 320132 a random number, no product in the database. It changes the URI to
http: // Domain.com /index.php?main_page=product_info&products_id=320132, genrating the following error

[26-Dec-2013 11:19:07 America] PHP Fatal error: Call to a member function RecordCount() on a non-object in /public_html/includes/modules/category_row.php on line 18

Thank you.

26 Dec 2013, 7:31 PM
#9
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Redirect discontinued items

stevesh:

The easy way would be to do it in the database, but I'm not SQL expert enough to write the patch. I suspect twitchtoo is.

Me neither.

But this is a huge issue for discontinued items, that are already bookmarked by site customers and indexed by search engines!

26 Dec 2013, 8:45 PM
#10
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: Redirect discontinued items

Kevin205, you're saying that you replaced the noproducts page with tpl_index_categories.php and it worked - correct?

Now you're asking to troubleshoot URI mapping issues?

26 Dec 2013, 10:09 PM
#11
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Redirect discontinued items

Kevin205:

Thank you twitchtoo for the reply,

I tried your solution, replacing tpl_product_info_noproduct.php with the following files:
includes/templates/MyTemplate/templates/tpl_index_default.php
Stopped displaying page info, including navigation breadcrumbs. Showing a blank center page. With the following error:

includes/templates/MyTemplate/templates/tpl_index_product_list.php
Displays the following warning after the nav breadcrumbs:
WARNING: An Error occurred, please refresh the page and try again.
Stopped displaying the rest of the page. Showing a blank center page. With the following error:

includes/templates/MyTemplate/templates/tpl_index_categories.php
Replacing the above file works :D, displaying the navigation breadcrumbs and sub-category name only, plus all other page information, all the the way down to the footer.

But when I change the URI to
http: // Domain.com /index.php?main_page=product_info&cPath=2_5&products_id=320132, id= 320132 a random number, no product in the database. It changes the URI to
http: // Domain.com /index.php?main_page=product_info&products_id=320132, genrating the following error

Thank you.

When you say you replaced the files, did you mean that you copied one file over another, or in

includes/modules/pages/product_info/main_template_vars.php

did you simply replace

$tpl_page_body = '/tpl_product_info_noproduct.php';

With

$tpl_page_body = '/tpl_index_default.php';

? I haven't tried that myself, but if you copied the files like it seems you did, then that would seem to explain the error messages.

Btw, agree, my attempt to offer a solution was one of a completely missing page, not a discontinued/disabled product.

26 Dec 2013, 10:37 PM
#12
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Redirect discontinued items

mc12345678:

When you say you replaced the files, did you mean that you copied one file over another, or in

includes/modules/pages/product_info/main_template_vars.php

did you simply replace

$tpl_page_body = '/tpl_product_info_noproduct.php';

With

$tpl_page_body = '/tpl_index_default.php';

? I haven't tried that myself, but if you copied the files like it seems you did, then that would seem to explain the error messages.

Btw, agree, my attempt to offer a solution was one of a completely missing page, not a discontinued/disabled product.

Sorry for that. In the working case; from what I understood from twitchtoo's post,
I replaced

if ( $res->fields['total'] < 1 ) {

$tpl_page_body = '/tpl_product_info_noproduct.php';

} else {

$tpl_page_body = '/tpl_product_info_display.php';

with

if ( $res->fields['total'] < 1 ) {

$tpl_page_body = '/tpl_index_categories.php';

} else {

$tpl_page_body = '/tpl_product_info_display.php';
27 Dec 2013, 4:13 AM
#13
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: Redirect discontinued items

Kevin205, yes you were right to change one line of code, not shuffle files around. So now that it's working you'd like the URI mapping looked at?

I need to know which URI module you have installed?

There is a php statement that's either missing the cPath expression in it or the cPath search is not being passed to the URI module to be published correctly.

27 Dec 2013, 3:10 PM
#14
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Redirect discontinued items

twitchtoo:

Kevin205, yes you were right to change one line of code, not shuffle files around. So now that it's working you'd like the URI mapping looked at?

I need to know which URI module you have installed?

There is a php statement that's either missing the cPath expression in it or the cPath search is not being passed to the URI module to be published correctly.

Kevin205:

But when I change the URI to
http: // Domain.com /index.php?main_page=product_info&cPath=2_5&products_id=320132, id= 320132 a random number, no product with that id, in the database. It changes the URI to
http: // Domain.com /index.php?main_page=product_info&products_id=320132, genrating the following error

I am NOT using any URI package.

As you see in the path, it is directly from Zen Cart. The cPath gets truncated when a wrong product "id" gets queried!

Thank you.

27 Dec 2013, 3:25 PM
#15
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Redirect discontinued items

Kevin205:

I am NOT using any URI package.

As you see in the path, it is directly from Zen Cart. The cPath gets truncated when a wrong product "id" gets queried!

Thank you.

As an FYI, the fact that don't have a URI rewriter is as much information as indicating which one you have. Typical rewriters still "function" with knowing the standard ZC URI format.

That said, I'm not surprised to see the effect of losing the cPath because afterall, the cPath indicates which category the product is in. In this case, the product does not exist, therefore is not in any cPath, and in essence would go to the noproduct page, which now is being redirected back to the categories page, where the product doesn't exist to be looked up.

Mentally and without looking at the details, it appears that the system is setup to be in a loop, though I would expect some sort of "break" or perhaps that's what twitchtoo is/was considering. Because of what I perceive is a loop, what affects are there other than a logged message of trying your non-existent product? Does the same thing occur if the product is merely disabled? (Ie, review product catalog for a product that is in the list, but is turned off from display to customers, and try that product number. Same error?)

27 Dec 2013, 4:37 PM
#16
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: Redirect discontinued items

Here's what's happening...
Client:
Finds product T, likes product T, bookmarks product T

Admin:
No longer offers product T.

Client:
Wants to buy product T cause now they have the money!

If Admin 'disables' the product and has changed the noproduct.php to the index_categories.php...
It will revert back to the index or category landing page the product used to be in.

If Admin 'deletes' the product from the database...
Everything fails.

So, I put the noproduct.php back in and found that the message 'Sorry, the product was not found' will display properly. However the 'back' or 'continue' button does not display.

<div class="centerColumn" id="productInfoNoProduct"> <div id="productInfoNoProductMainContent" class="content"><?php echo TEXT_PRODUCT_NOT_FOUND; ?></div> <div class="buttonRow back"><?php zen_back_link() . zen_image_button(BUTTON_IMAGE_CONTINUE, BUTTON_CONTINUE_ALT) . '</a>'; ?></div>

Meaning it's not coded correctly or it's not getting any data to 'go back' or 'continue' to which makes sense.

So, the alternate solution here would be to leave the message on the noproducts.php and add the code needed to go somewhere.

It would be clean, fast and prevent any future problems if any of the files involved were to be changed. It would also be consistent, regardless of a 'disabled' or 'deleted' product the redirect would return to a controlled location.

in includes/templates/YOUR_TEMPLATE/templates/tpl_product_info_noproduct.php
replace line 18:

<div class="buttonRow back"><?php zen_back_link() . zen_image_button(BUTTON_IMAGE_CONTINUE, BUTTON_CONTINUE_ALT) . '</a>'; ?></div>

with this:

<?php // Twitch No Product Continue to Index ?> <div class="buttonRow back"><?php echo '<a href="' . HTTP_SERVER . DIR_WS_CATALOG . '">'; ?><?php echo zen_image_button(BUTTON_IMAGE_CONTINUE);?></a></div> <!-- <div class="buttonRow back"><?php //zen_back_link() . zen_image_button(BUTTON_IMAGE_CONTINUE, BUTTON_CONTINUE_ALT) . '</a>'; ?></div>-->

it will look like this:
Attachment 13604
and clicking the continue button will take you home. The customer can read the message, understand why they can't see what they want and decide to move on or perhaps select a new category in the category sidebox.

27 Dec 2013, 5:02 PM
#17
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Redirect discontinued items

twitchtoo:

Here's what's happening...
Client:
Finds product T, likes product T, bookmarks product T

Admin:
No longer offers product T.

Client:
Wants to buy product T cause now they have the money!

If Admin 'disables' the product and has changed the noproduct.php to the index_categories.php...
It will revert back to the index or category landing page the product used to be in.

If Admin 'deletes' the product from the database...
Everything fails.

So, I put the noproduct.php back in and found that the message 'Sorry, the product was not found' will display properly. However the 'back' or 'continue' button does not display.

<div class="centerColumn" id="productInfoNoProduct"> <div id="productInfoNoProductMainContent" class="content"><?php echo TEXT_PRODUCT_NOT_FOUND; ?></div> <div class="buttonRow back"><?php zen_back_link() . zen_image_button(BUTTON_IMAGE_CONTINUE, BUTTON_CONTINUE_ALT) . '</a>'; ?></div>

Meaning it's not coded correctly or it's not getting any data to 'go back' or 'continue' to which makes sense.

So, the alternate solution here would be to leave the message on the noproducts.php and add the code needed to go somewhere.

It would be clean, fast and prevent any future problems if any of the files involved were to be changed. It would also be consistent, regardless of a 'disabled' or 'deleted' product the redirect would return to a controlled location.

in includes/templates/YOUR_TEMPLATE/templates/tpl_product_info_noproduct.php
replace line 18:

<div class="buttonRow back"><?php zen_back_link() . zen_image_button(BUTTON_IMAGE_CONTINUE, BUTTON_CONTINUE_ALT) . '</a>'; ?></div>

with this:

<?php // Twitch No Product Continue to Index ?> <div class="buttonRow back"><?php echo '<a href="' . HTTP_SERVER . DIR_WS_CATALOG . '">'; ?><?php echo zen_image_button(BUTTON_IMAGE_CONTINUE);?></a></div> <!-- <div class="buttonRow back"><?php //zen_back_link() . zen_image_button(BUTTON_IMAGE_CONTINUE, BUTTON_CONTINUE_ALT) . '</a>'; ?></div>-->

it will look like this:
Attachment 13604
and clicking the continue button will take you home. The customer can read the message, understand why they can't see what they want and decide to move on or perhaps select a new category in the category sidebox.

I would say that the above solution is probably more on target with what would be expected. There are a few other zen Cart functions that could be used to obtain the same result, especially the Url creation for the button. I think there is a zen_submit_button or zen_button_submit option that can be fed the destination and image and will do most of what that line does.

Otherwise, part of the redirect solution should "clear" the product/category information so that the guest goes to some other page like was trying before. Now, that said, twitchtoo does bring it back to home by keeping the "guest" informed about what is going on rather than just flinging them around to different areas of your site. Perhaps even more information could be provided on the noproduct page, in text or in hyperlinks. I thought there might be a redirect to sitemap option also that could be taken advantage of.

27 Dec 2013, 5:38 PM
#18
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Redirect discontinued items

mc12345678:

As an FYI, the fact that don't have a URI rewriter is as much information as indicating which one you have. Typical rewriters still "function" with knowing the standard ZC URI format.

Good to know. Thanks.

27 Dec 2013, 5:39 PM
#19
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Redirect discontinued items

twitchtoo:

So, the alternate solution here would be to leave the message on the noproducts.php and add the code needed to go somewhere.

It would be clean, fast and prevent any future problems if any of the files involved were to be changed. It would also be consistent, regardless of a 'disabled' or 'deleted' product the redirect would return to a controlled location.

in includes/templates/YOUR_TEMPLATE/templates/tpl_product_info_noproduct.php
replace line 18:

<div class="buttonRow back"><?php zen_back_link() . zen_image_button(BUTTON_IMAGE_CONTINUE, BUTTON_CONTINUE_ALT) . '</a>'; ?></div>

with this:

<?php // Twitch No Product Continue to Index ?> <div class="buttonRow back"><?php echo '<a href="' . HTTP_SERVER . DIR_WS_CATALOG . '">'; ?><?php echo zen_image_button(BUTTON_IMAGE_CONTINUE);?></a></div> <!-- <div class="buttonRow back"><?php //zen_back_link() . zen_image_button(BUTTON_IMAGE_CONTINUE, BUTTON_CONTINUE_ALT) . '</a>'; ?></div>-->

it will look like this:
Attachment 13604
and clicking the continue button will take you home. The customer can read the message, understand why they can't see what they want and decide to move on or perhaps select a new category in the category sidebox.

It sounds great to me.

I will give it try and keep you posted. Thank you.

ps. Nice car.

27 Dec 2013, 7:00 PM
#20
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Redirect discontinued items

twitchtoo and mc12345678, problem solved.

Thank you.