Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

why doesnt this code work?


hatimad

Recommended Posts

Hello,

 

can anyone please explain to me why this code doesnt show sub-category when there is product in main category?

 

it shows subcategories otherwise

 

can it be modified to show subcategory even when there is products in main category

 

thank you

 

<?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 .= '<br>';

 show_subcategories($fooa[$counter]['next_id']);

}else{

 $subcategories_string .= ' ';

}

}

?>



<?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]);



 echo $subcategories_string;

}else{

 echo " ";

}



?>

Link to comment
Share on other sites

Your problem has nothing to do with the code you posted. It has to do with the code in default.php which only allows you to show sub-categories if there are no products defined. It is a flaw in the program design in my opinion.

Link to comment
Share on other sites

i figured out, the problem was not in default.php

 

the problem was in

   if ($id[0][0] != ''){ 

     show_subcategories($id[0][0]);

 

this was only taking first caracter of category id

 

that is if category id was 2 it will show 2 and if category id was 24 it will still show 2

 

i changed it to

	if ($id[0] != ''){

 show_subcategories($id[0]);

 

and it works now and hopefully it wont create any complication

 

thanks

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...