Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

if Statement for Category Not Found


mommaroodles

Recommended Posts

I'm sitting with a bit of a dillemma - not sure how to to do this.

 

With categories - if you have a category with NO products in the category - the category name will appear in the categories box and if you click on it - provided you have the categories ht_title tag turn on, you will see the category's name with the message "There are no products available in this category." and this is all fine and well. The categories name is enclosed in a <h1> tag and that one finds at this section of the index.php file

 

   $catname = HEADING_TITLE;
   if (isset($_GET['manufacturers_id']) && !empty($_GET['manufacturers_id'])) {
  $image = tep_db_query("select manufacturers_image, manufacturers_name as catname from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$_GET['manufacturers_id'] . "'");
  $image = tep_db_fetch_array($image);
  $catname = $image['catname'];
   } elseif ($current_category_id) {
  $image = tep_db_query("select c.categories_image, cd.categories_name as catname from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = '" . (int)$current_category_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "'");
  $image = tep_db_fetch_array($image);
  $catname = $image['catname'];
   }
?>
<h1><?php echo $catname; ?></h1>

 

Now in the event that someone should click on an old categories link that no longer exists at all - meaning that id does not exist in the database at all, irrespective of whether its a parent category or sub-category - what happens is that what is returned is still the "There are no products available in this category." BUT - the <h1> tag is empty.

 

If I look at my source code - I see this

 

<h1></h1>
<div class="contentContainer">
  <div class="contentText">
 <p class="main">There are no products available in this category.</p>

 

What I am trying to find out is how to construct that if statement in this code block

 

   $catname = HEADING_TITLE;
   if (isset($_GET['manufacturers_id']) && !empty($_GET['manufacturers_id'])) {
  $image = tep_db_query("select manufacturers_image, manufacturers_name as catname from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$_GET['manufacturers_id'] . "'");
  $image = tep_db_fetch_array($image);
  $catname = $image['catname'];
   } elseif ($current_category_id) {
  $image = tep_db_query("select c.categories_image, cd.categories_name as catname from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = '" . (int)$current_category_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "'");
  $image = tep_db_fetch_array($image);
  $catname = $image['catname'];
   }

?>

<?php  if something or other { ?>

<h1><?php echo TEXT_NOT_FOUND; ?></h1>

<?php } else { ?>

<h1><?php echo $catname; ?></h1>

<?php } ?>

 

I've tried all sorts if categories total > 1 and a few others and its not working. The TEXT_NOT_FOUND define is in the english/index.php file so provision has been made, but it doesnt appear anywhere.

 

The reason this is important is that I have styling attached to that h1 and in the event someone clicking on a non existing category, one can clearly see that something is missing on the page and it's looking odd - very odd and I just dont like the idea of the empty <h1> tag on the page.

 

I'd really appreciate some assistance :)

"The doorstep to the temple of wisdom is a knowledge of our own ignorance."

Link to comment
Share on other sites

ah ok found it this works now for me

 

<?php if ($categories['total'] < 1) { ?>
<h1 class="line"><?php echo TEXT_NOT_FOUND; ?></h1>
<?php } else { ?>
<h1 class="line"><?php echo $catname; ?></h1>
<?php } ?>

 

not working - now its showing category not found even if the category is listed but just with no products

"The doorstep to the temple of wisdom is a knowledge of our own ignorance."

Link to comment
Share on other sites

I'm not sure I understand the problem but it sounds like you are saying that if you delete a category it still shows up in the category box. Is that correct? If so, then your category box is probably loading from cache because that shouldn't happen. Try turning off the cache option in admin or, if you have some altered categories box with its own cache, disable that to see if the problem goes away.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

No, i'm not saying that if you delete it it still shows up in the categories box. What I am saying is that whether or not you delete it or if by some chance someone mistakenly clicks on a link reflecting an category id which does not exist at all - you get the " there are not products available in this category - but then if you look at the source code - you will see an empty <h1> tag - now that empty heading one tag, I need to fill that with a heading so if have

 

<h1>CATEGORY NOT FOUND</H1>

<p>there are not products available in this category</p>

"The doorstep to the temple of wisdom is a knowledge of our own ignorance."

Link to comment
Share on other sites

take a look at this link http://demo.oscommerce.com/index.php?cPath=356 then look at the source code - you'll see

 

<div id="bodyContent" class="grid_16 push_4">
<h1></h1>
<div class="contentContainer">

<div class="contentText">

<p>There are no products available in this category.</p>

</div>

 

that cPath=356 doesnt exist in the database

"The doorstep to the temple of wisdom is a knowledge of our own ignorance."

Link to comment
Share on other sites

No, i'm not saying that if you delete it it still shows up in the categories box. What I am saying is that whether or not you delete it or if by some chance someone mistakenly clicks on a link reflecting an category id which does not exist at all - you get the " there are not products available in this category - but then if you look at the source code - you will see an empty <h1> tag - now that empty heading one tag, I need to fill that with a heading so if have

As mentioned, it shouldn't be possible to click on a non-existent link but maybe you are referring to a link in from some external source, like google. The problem is that the code in oscommerce tries to load the category page and when it can't be found, it lists the standard not found message and issues a 302 status. So if the link is coming from somewhere like google, it will never be fixed and changing what text is displayed just covers up the problem. The correct fix is to install the Header Status Handler. That will redirect missing categories, and products, to a proper not found page and will issue a 410 status code, which will cause it to be removed from the source, assuming the source is a search engine listing.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

As mentioned, it shouldn't be possible to click on a non-existent link but maybe you are referring to a link in from some external source, like google. The problem is that the code in oscommerce tries to load the category page and when it can't be found, it lists the standard not found message and issues a 302 status. So if the link is coming from somewhere like google, it will never be fixed and changing what text is displayed just covers up the problem. The correct fix is to install the Header Status Handler. That will redirect missing categories, and products, to a proper not found page and will issue a 410 status code, which will cause it to be removed from the source, assuming the source is a search engine listing.

 

It is possible to click on a non existant link from google as you say - but I'm also in the process of customising the noindex meta tags and in an event like this - the meta-tag will change to noindex :)

"The doorstep to the temple of wisdom is a knowledge of our own ignorance."

Link to comment
Share on other sites

What I've actually done is - the upcoming products module - of which my client has a stacks - I've made that display just below the "no products avail in this category" message so that a potential customer can see when the relevant products will be expected.

"The doorstep to the temple of wisdom is a knowledge of our own ignorance."

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...