Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Bug with breadcrumbs and cPath=0 ?


nfrobertson

Recommended Posts

Posted

I want to use the cPath=0 from a button to display the entire list of categories in the center. It is working (once I turned off the images required option under configure|images) but the breadcrumbs were not working.

 

If I start at cPath=0 then click additional categories, the breadcrumbs wouldn't grow correctly.

 

Start with this on a typical new install:

http://localhost/catalog/index.php?cPath=0

 

Then click one of the categories in the middle (not the info boxes) for example:

http://localhost/catalog/index.php?cPath=0_2

 

Notice that "Software" doesn't get added to the breadcrumbs. "Software" is the category name for 2.

 

 

I've tracked this down to a small bit of code in application_top.php where it goes to get the names of all the categories. Well, category 0 (cPath=0) doesn't have a name. The way the code is written it just stops looking for more names. This is why it breaks if you start at cPath=0 then click on subcategories (see the 0_2 in the link above)

 

Here's the code:

 

// add category names or the manufacturer name to the breadcrumb trail
 if (isset($cPath_array)) {
for ($i=0, $n=sizeof($cPath_array); $i<$n; $i++) {
  $categories_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . (int)$cPath_array[$i] . "' and language_id = '" . (int)$languages_id . "'");
  if (tep_db_num_rows($categories_query) > 0) {
	$categories = tep_db_fetch_array($categories_query);
	$breadcrumb->add($categories['categories_name'], tep_href_link(FILENAME_DEFAULT, 'cPath=' . implode('_', array_slice($cPath_array, 0, ($i+1)))));
  } else {
	break;
  }
}
 } elseif (isset($HTTP_GET_VARS['manufacturers_id'])) {
$manufacturers_query = tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "'");
if (tep_db_num_rows($manufacturers_query)) {
  $manufacturers = tep_db_fetch_array($manufacturers_query);
  $breadcrumb->add($manufacturers['manufacturers_name'], tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id']));
}
 }

 

See the "break;" about in the middle? Comment it out to look like:

 

	  } else {
	//break;
  }

 

And the breadcrumbs will work again.

 

Basically this tries to look up the name for 0, doesn't find it, then instead of giving up (break;) it continues in the loop looking for any other category names.

 

Has anyone else seen this? Anyone have a cautionary tale as to why commenting out the break; would be bad?

 

Thanks!

Nathan

  • 2 years later...
Posted
I want to use the cPath=0 from a button to display the entire list of categories in the center. It is working (once I turned off the images required option under configure|images) but the breadcrumbs were not working.

 

If I start at cPath=0 then click additional categories, the breadcrumbs wouldn't grow correctly.

 

Start with this on a typical new install:

http://localhost/catalog/index.php?cPath=0

 

Then click one of the categories in the middle (not the info boxes) for example:

http://localhost/catalog/index.php?cPath=0_2

 

Notice that "Software" doesn't get added to the breadcrumbs. "Software" is the category name for 2.

 

 

I've tracked this down to a small bit of code in application_top.php where it goes to get the names of all the categories. Well, category 0 (cPath=0) doesn't have a name. The way the code is written it just stops looking for more names. This is why it breaks if you start at cPath=0 then click on subcategories (see the 0_2 in the link above)

 

Here's the code:

 

// add category names or the manufacturer name to the breadcrumb trail
 if (isset($cPath_array)) {
for ($i=0, $n=sizeof($cPath_array); $i<$n; $i++) {
  $categories_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . (int)$cPath_array[$i] . "' and language_id = '" . (int)$languages_id . "'");
  if (tep_db_num_rows($categories_query) > 0) {
	$categories = tep_db_fetch_array($categories_query);
	$breadcrumb->add($categories['categories_name'], tep_href_link(FILENAME_DEFAULT, 'cPath=' . implode('_', array_slice($cPath_array, 0, ($i+1)))));
  } else {
	break;
  }
}
 } elseif (isset($HTTP_GET_VARS['manufacturers_id'])) {
$manufacturers_query = tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "'");
if (tep_db_num_rows($manufacturers_query)) {
  $manufacturers = tep_db_fetch_array($manufacturers_query);
  $breadcrumb->add($manufacturers['manufacturers_name'], tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id']));
}
 }

 

See the "break;" about in the middle? Comment it out to look like:

 

	  } else {
	//break;
  }

 

And the breadcrumbs will work again.

 

Basically this tries to look up the name for 0, doesn't find it, then instead of giving up (break;) it continues in the loop looking for any other category names.

 

Has anyone else seen this? Anyone have a cautionary tale as to why commenting out the break; would be bad?

 

Thanks!

Nathan

 

Nathan, you're a genius! I was trying to figure this out and your solution works 100%. It wasn't just the breadcrumbs wouldn't grow correctly, but also the rest of the subcategories info (category picture, metadata etc.)

 

Now everything works perfectly and so far I haven't seen any negative effects to commenting out the break.

 

Thanks again mate!

  • 1 month later...
Posted
Nathan, you're a genius! I was trying to figure this out and your solution works 100%. It wasn't just the breadcrumbs wouldn't grow correctly, but also the rest of the subcategories info (category picture, metadata etc.)

 

Now everything works perfectly and so far I haven't seen any negative effects to commenting out the break.

 

Thanks again mate!

 

Going to try this. Thanks.

Archived

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

×
×
  • Create New...