Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Recommended Posts

Posted

Hi Guys,

 

I am using the Category Tabs with Subs contribution and am having problems with it.

 

My site has 2 levels of categories, main and sub.

 

I noticed if the main category ID is only 1 digit long the sub catgory strip displays the sub categories. However I noticed on some main categories that I clicked on (that DO have subcategories) didn't display the sub categories. I then looked further (head banging) to see if I could find out why SOME main categories displayed the sub categories while others didn't.

 

First I looked in the admin to double check the categories and yes ALL main categories have sub-categories (only 1 level deep) and all sub-catgeories have products (no main categories do BTW).

 

I then looked at the categories_tab.php file to see if I could debug it. I think I have foudbn the pub but don't know how to solve it.

 

Firstly the oub is with main categories that have an ID greater than 1 digit in length (ie.21, 25 etc), these are the problem main categories. Categies with an ID of 1 digit length work OK!

 

Looking at the code I could see that somehow a 2 digit ID (for teh main categories) was being referenced as ONLY by the first digit of the id (ie.25 was being referenced as 2). This problem occurs where the code on line 230 (see below) calls

$id[0][0

.

 

When doing an echo of the value for the $id[0][0] for 1 digit length categories ids it is fine, but for 2 digit length categories ids it is only returning the first digit of the category ID.

 

The complete (unmodified) code for the category sub with tabs can be seen below. Can any of you out there spot where or why in teh below code the 2 digit categoy IDs are getting trimmed to 1 digit? (I added a comment next to the line that is returning the wrong category id for 2+ digit length category IDs).

 

<?php
/*
 $Id: categories.php,v 1.1.1.1 2003/02/25 02:59:49 root Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2002 osCommerce

 Released under the GNU General Public License
*/

function show_category_tabs($counter) 
{
global $foo, $categories_string, $id, $HTTP_GET_VARS;
if ($foo[$counter]['parent'] == 0) {
 $cPath_new = 'cPath=' . $counter;
}
if ($HTTP_GET_VARS['cPath'] != 0){
 $base = substr($HTTP_GET_VARS['cPath'], 0, strpos($HTTP_GET_VARS['cPath'], '_'));
 if ($counter == $HTTP_GET_VARS['cPath']) {
	 $onpage = 1;
 } elseif ($counter == $base) {
	 $onpage = 1;
 }
}

if ($onpage) {
 $categories_string .= '<td valign="top" class="headerNavigation">';
} else {
 $categories_string .= '<td valign="top" class="inactiveNavigation">';
} 	 

$categories_string .= tep_image(DIR_WS_IMAGES . 'trans_corner_left.gif', ''); 
$categories_string .= '</td>';
if ($onpage) {
 $categories_string .= '<td valign="top" class="headerNavigation">';
} else {
 $categories_string .= '<td valign="top" class="inactiveNavigation">';
} 	 

$categories_string .= '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top" bgcolor="#ffffff">';
$categories_string .= tep_image(DIR_WS_IMAGES . 'pixel_trans.gif', '');
$categories_string .= '</td></tr><tr><td valign="top" bgcolor="#C0C0C0">';
$categories_string .= tep_image(DIR_WS_IMAGES . 'pixel_trans.gif', '');
$categories_string .= '</td></tr></table><a href="';
$categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new);
if ($onpage) {
 $categories_string .= '"  class="headerNavigation">';
} else {
 $categories_string .= '" class="inactiveNavigation">';
}
// display category name
$categories_string .= $foo[$counter]['name'];

$categories_string .= '</a>  </td>';
if ($onpage) {
 $categories_string .= '<td valign="top" class="headerNavigation">';
} else {
 $categories_string .= '<td valign="top" class="inactiveNavigation">';
} 	 

$categories_string .= tep_image(DIR_WS_IMAGES . 'trans_corner_right.gif', '');
$categories_string .= '</td>';

if ($foo[$counter]['next_id']) {
 $onpage = 0;
 show_category_tabs($foo[$counter]['next_id']);
}
}
?>


<?php
function show_subcategories($counter) 
{
global $fooa, $subcategories_string, $id, $HTTP_GET_VARS;
$cPath_new = 'cPath=' . $fooa[$counter]['path'];

$subcategories_string .= '<a href="';
$subcategories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new);
$subcategories_string .= '"  class="headerNavigation">';

// display category name
$subcategories_string .= $fooa[$counter]['name'];

$subcategories_string .= '</a> ';

if ($fooa[$counter]['next_id']) {
 $subcategories_string .= '| ';
 show_subcategories($fooa[$counter]['next_id']);
}else{
 $subcategories_string .= ' ';
}

}
?>


<!-- categories //-->
<table border="0" cellspacing="0" cellpadding="0" bgcolor="#000080">
<tr>
<?php
// Always add the home link first
$categories_string = '';
if (!$cPath) {
 $onpage = 1;
}
if ($onpage) {
 $categories_string .= '<td valign="top" class="headerNavigation">';
} else {
 $categories_string .= '<td valign="top" class="inactiveNavigation">';
} 	 

$categories_string .= tep_image(DIR_WS_IMAGES . 'trans_corner_left.gif', ''); 
$categories_string .= '</td>';
if ($onpage) {
 $categories_string .= '<td valign="top" class="headerNavigation">';
} else {
 $categories_string .= '<td valign="top" class="inactiveNavigation">';
} 	 

$categories_string .= '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top" bgcolor="#ffffff">';
$categories_string .= tep_image(DIR_WS_IMAGES . 'pixel_trans.gif', '');
$categories_string .= '</td></tr><tr><td valign="top" bgcolor="#C0C0C0">';
$categories_string .= tep_image(DIR_WS_IMAGES . 'pixel_trans.gif', '');
$categories_string .= '</td></tr></table><a href="';
$categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new);
if ($onpage) {
 $categories_string .= '"  class="headerNavigation">';
} else {
 $categories_string .= '" class="inactiveNavigation">';
}
// display category name
$categories_string .= "Home";

$categories_string .= '</a>  </td>';
if ($onpage) {
 $categories_string .= '<td valign="top" class="headerNavigation">';
} else {
 $categories_string .= '<td valign="top" class="inactiveNavigation">';
} 	 

$categories_string .= tep_image(DIR_WS_IMAGES . 'trans_corner_right.gif', '');
$categories_string .= '</td>';

if ($foo[$counter]['next_id']) {
 $onpage = 0;
 show_category_tabs($foo[$counter]['next_id']);
}

// start the tabs
$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . $languages_id ."' order by sort_order, cd.categories_name");
while ($categories = tep_db_fetch_array($categories_query))  {
 $foo[$categories['categories_id']] = array(
	 'name' => $categories['categories_name'],
	 'parent' => $categories['parent_id'],
	 'level' => 0,
	 'path' => $categories['categories_id'],
	 'next_id' => false
 );

 if (isset($prev_id)) {
	 $foo[$prev_id]['next_id'] = $categories['categories_id'];
 }

 $prev_id = $categories['categories_id'];

 if (!isset($first_element)) {
	 $first_element = $categories['categories_id'];
 }
}

show_category_tabs($first_element); 
echo $categories_string;

?>
</tr>
</table>
         
<!-- categories_eof //-->


<!-- subcategories //-->
<table border="0" cellspacing="0" cellpadding="4" WIDTH="100%">
<tr class="headerNavigation"><td ALIGN="CENTER" class="headerNavigation">
<?php
if ($cPath) {
 $subcategories_string = '';
 $new_path = '';
 $id = split('_', $cPath);
 reset($id);
 while (list($key, $value) = each($id)) {
	 unset($prev_id);
	 unset($first_id);
	 $subcategories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . $value . "' and c.categories_id = cd.categories_id and cd.language_id='" . $languages_id ."' order by sort_order, cd.categories_name");
	 $subcategory_check = tep_db_num_rows($subcategories_query);
	 if ($subcategory_check > 0) {
   $new_path .= $value;
   while ($row = tep_db_fetch_array($subcategories_query)) {
  	 $fooa[$row['categories_id']] = array(
     'name' => $row['categories_name'],
     'parent' => $row['parent_id'],
     'level' => $key+1,
     'path' => $new_path . '_' . $row['categories_id'],
     'next_id' => false
  	 );
  	 if (isset($prev_id)) {
     $fooa[$prev_id]['next_id'] = $row['categories_id'];
  	 }

  	 $prev_id = $row['categories_id'];
  	 
  	 if (!isset($first_id)) {
     $first_id = $row['categories_id'];
  	 }

  	 $last_id = $row['categories_id'];
   }
   $fooa[$last_id]['next_id'] = $fooa[$value]['next_id'];
   $fooa[$value]['next_id'] = $first_id;
   $new_path .= '_';
	 } else {
   break;
	 }
 }
}

if ($id[0][0] != ''){
 show_subcategories($id[0][0]); //THIS IS THE VARIABLE/ARRAY THAT FOR SOME REASON IS CONVERTING A 2 DIGIT CATEGORY ID TO 1 DIGIT.
 echo $subcategories_string;
}else{
 echo " ";
}

?>
</td>
</tr>
</table>
         
<!-- subcategories_eof //-->

 

Any help with this would be appreciated. :D

Posted (edited)

Ohh yeah of the code supplied in my last post, only the code below the :

<!-- subcategories //-->

..is probably of interest.

 

Again thanks, hope someone can help.

Edited by Lucky Bastard

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...