Forums / General Questions / What files control the 404 product not found?

What files control the 404 product not found?

Started by philip937 on 12 Oct 2014, 12:18 PM · Views: 1,555

Results 1 to 14 of 14
12 Oct 2014, 12:18 PM
#1
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

What files control the 404 product not found?

Hi all, I touched on this quite some time ago but can't seem to find the thread.

I want to change the behaviour of my site when products are disabled. Instead of displaying the product not found page and issuing a 404 message, I want the product to display as normal.

So essentially, all I want disabling a product to do is for it to not be listed in the front facing catalogue and thus ensuring that the original link tot the item (whilst the id exists) still works. meaning that if someone shared a link somewhere to an old product, I still want that link to work and display the product.

so as a start, in the following file:

includes/modules/pages/product_info/header_php.php

this code:

 // if specified product_id is disabled or doesn't exist, ensure that metatags and breadcrumbs don't share inappropriate information
  $sql = "select count(*) as total
          from " . TABLE_PRODUCTS . " p, " .
                   TABLE_PRODUCTS_DESCRIPTION . " pd
          where    p.products_status = '1'
          and      p.products_id = '" . (int)$_GET['products_id'] . "'
          and      pd.products_id = p.products_id
          and      pd.language_id = '" . (int)$_SESSION['languages_id'] . "'";
  $res = $db->Execute($sql);
  if ( $res->fields['total'] < 1 ) {
   unset($_GET['products_id']);
    unset($breadcrumb->_trail[sizeof($breadcrumb->_trail)-1]['title']);
    $robotsNoIndex = true;
    header('HTTP/1.1 404 Not Found');
  }

I assume I just remove the p.products_status = '1' WHERE clause and that will remove the 404 bit?

Thats just the start, can someone point me to ALL the other places I need to make a similar change so that the page displays correctly even when the product is disabled?

Many Thanks

Phil

Phil Rogers
A problem shared is a problem solved.

12 Oct 2014, 1:20 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: What files control the 404 product not found?

philip937:

Hi all, I touched on this quite some time ago but can't seem to find the thread.

I want to change the behaviour of my site when products are disabled. Instead of displaying the product not found page and issuing a 404 message, I want the product to display as normal.

So essentially, all I want disabling a product to do is for it to not be listed in the front facing catalogue and thus ensuring that the original link tot the item (whilst the id exists) still works. meaning that if someone shared a link somewhere to an old product, I still want that link to work and display the product.

so as a start, in the following file:

includes/modules/pages/product_info/header_php.php

this code:

// if specified product_id is disabled or doesn't exist, ensure that metatags and breadcrumbs don't share inappropriate information
$sql = "select count(*) as total
from " . TABLE_PRODUCTS . " p, " .
TABLE_PRODUCTS_DESCRIPTION . " pd
where p.products_status = '1'
and p.products_id = '" . (int)$_GET['products_id'] . "'
and pd.products_id = p.products_id
and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'";
$res = $db->Execute($sql);
if ( $res->fields['total'] < 1 ) {
unset($_GET['products_id']);
unset($breadcrumb->_trail[sizeof($breadcrumb->_trail)-1]['title']);
$robotsNoIndex = true;
header('HTTP/1.1 404 Not Found');
}

> 
> I assume I just remove the p.products_status = '1' WHERE clause and that will remove the 404 bit?
> 
> Thats just the start, can someone point me to ALL the other places I need to make a similar change so that the page displays correctly even when the product is disabled?
> 
> Many Thanks
> 
> Phil

Maybe it's just "luck" that this one snippet of code was used, but looks like the intent is to try to game the system about what is offered on the site. 

Have you ever shopped at a site where it is impossible to find the thing that got you to the site other than from some external site?  If the real intent is to target customers, I hope when that product is disabled that there is some good information about the situation as it sounds like once on the site at that product that can't be purchased because it no longer exists, it can never be found on the store again either as it won't display in the category(ies) in which it assigned.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

12 Oct 2014, 1:30 PM
#3
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: What files control the 404 product not found?

My question was about zen cart code. I am not sure I understand your response?

Phil Rogers
A problem shared is a problem solved.

12 Oct 2014, 1:40 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: What files control the 404 product not found?

philip937:

My question was about zen cart code. I am not sure I understand your response?

Sorry, the short of it is: Why? Please explain.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

12 Oct 2014, 1:44 PM
#5
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: What files control the 404 product not found?

Why what? Why do I want my URL to display useful information? Because someone landing on a white 404 page (or even a generic custom 404 page) is not helpful and a potential customer will bounce 99.99% of the time.

So the reasoning is that the user will land on a page where yes the product is no longer avaiable but will have custom code referring customers to newer and existing alternatives.

So the link remains useful.

Phil Rogers
A problem shared is a problem solved.

12 Oct 2014, 1:51 PM
#6
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: What files control the 404 product not found?

philip937:

Why what? Why do I want my URL to display useful information? Because someone landing on a white 404 page (or even a generic custom 404 page) is not helpful and a potential customer will bounce 99.99% of the time.

So the reasoning is that the user will land on a page where yes the product is no longer avaiable but will have custom code referring customers to newer and existing alternatives.

So the link remains useful.

Sounds like then still have a custom '404' page, but without telling the internet machines that there is/was a '404' error. Why do that?

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

12 Oct 2014, 1:53 PM
#7
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: What files control the 404 product not found?

404 not found. If the page is there then it is found. To be honest the question wasn't asking advice on the logic, I was after the technical answer.

Phil Rogers
A problem shared is a problem solved.

12 Oct 2014, 2:09 PM
#8
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: What files control the 404 product not found?

philip937:

I assume I just remove the p.products_status = '1' WHERE clause and that will remove the 404 bit?

This assumption isn't *quite *correct.

Removing the p.products_status = '1' will include the disabled product in the count(*), and that will indeed cause the '404 bit' to be skipped, assuming the product is still in the DB, but if the product with the $_GET['products_id'] has been deleted the res->fields['total'] will still be < 1 and the '404 bit' will be acted upon.

This may or may not be what you are after.

Cheers
RodG

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

12 Oct 2014, 2:13 PM
#9
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: What files control the 404 product not found?

philip937:

404 not found. If the page is there then it is found. To be honest the question wasn't asking advice on the logic, I was after the technical answer.

My apologies that the thought is that asking a question necessitates an answer without discourse on the reasons and intentions. Heaven forbid that someone try to do something that appears as if involve a lot of work on their side to sustain or that appears to be trying to let search engines believe that the link previously found leads to the same content and really is a valid/useful link instead of a basic redirect without making it known that it is a redirect or any other type of non-existent product.

The solution is simple, and can be performed/determined from your own store's admin and some form of ftp/file manipulation tool. I'm still not convinced that the solution is one to which I feel it is right to give an answer and will allow another to offer the answer of pointing you to ALL the other places you need to make a similar change so that the page displays correctly even when the product is disabled?

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

12 Oct 2014, 2:14 PM
#10
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: What files control the 404 product not found?

Yes that pretty much what I'm after. So a disabled product will:

  • Not be visible in the product listings
  • Accessible via external links

A product deleted from database will:

  • Will return 404 not found

In addition to the above I need to find out what code I need to change so that the product info page displays normally with the content and page title etc.

Any ideas RodD?

Phil Rogers
A problem shared is a problem solved.

12 Oct 2014, 2:21 PM
#11
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: What files control the 404 product not found?

RodG:

This assumption isn't *quite *correct.

Removing the p.products_status = '1' will include the disabled product in the count(*), and that will indeed cause the '404 bit' to be skipped, assuming the product is still in the DB, but if the product with the $_GET['products_id'] has been deleted the res->fields['total'] will still be < 1 and the '404 bit' will be acted upon.

This may or may not be what you are after.

Cheers
RodG

Based on the original writeup: product disabled, still in database (not deleted), but not to be shown: products_id would still be valid, and so would everything else in the statement except a 404 would not be sent and one couldn't get to the product from the store side, could only get to the product (know that it currently exists) because it was found sometime in the past or is forwarded on now as an item of interest that has been disabled.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

12 Oct 2014, 2:32 PM
#12
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: What files control the 404 product not found?

Just a silly idea here ...

But ... wouldn't it be easier to have Products that are 0 stock that go to products_status = 0, be changed to NOT go to products_status = 0 and just be products_quantity = 0 which then is Sold Out and adapt the Catalog to not show Products that products_quantity = 0 where you do not want to see them?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

12 Oct 2014, 2:46 PM
#13
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: What files control the 404 product not found?

philip937:

Yes that pretty much what I'm after. So a disabled product will:

  • Not be visible in the product listings

This would be dependent on the product listings code / settings.
The proposed change to the product info page will have no effect on this.

philip937:

  • Accessible via external links

What happens here depends on the rest of the code for the product info page. The easiest way to determine this is to make the change and navigate to the product info page of the disabled product.

philip937:

A product deleted from database will:

  • Will return 404 not found

Only for the product info page.

philip937:

In addition to the above I need to find out what code I need to change so that the product info page displays normally with the content and page title etc.

Unless I'm mistaken, no other changes will be needed, but again, the best thing to do is try it.

Never be afraid to experiment with these things. Just make sure you only change one thing at a time and if you don't get the expected results change things back to how they were before moving on.
What you should not do is leave a change in place if no effect is noted as a result of the change. Doing this has a nasty habit of biting you in unexpected ways.

Cheers
RodG

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

12 Oct 2014, 2:52 PM
#14
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: What files control the 404 product not found?

Ajeh:

Just a silly idea here ...

But ... wouldn't it be easier to have Products that are 0 stock that go to products_status = 0, be changed to NOT go to products_status = 0 and just be products_quantity = 0 which then is Sold Out and adapt the Catalog to not show Products that products_quantity = 0 where you do not want to see them?

I have a feeling that this is what mc12345678 is/was trying to eke out of the OP.

I could be wrong.... or at best, a little confused other exactly what is trying to be achieved.
My aim here is to just answer the questions :)

Cheers
RodG

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.