Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

only show categories with active products??


dkennelly

Recommended Posts

Hi All,

I need to set up a store with loads of categories but most will be empty for now - anyone know how I can use the categories box to display only categories with active products?

Any help appreciated,

thanks, daithi.

Link to comment
Share on other sites

although you can change the code to join categories with products, I don't think it is wise to do this as it puts a heavy burden on your system.

I would install the enable/disable categories contribution which is a pretty easy install and it will not affect performance that much.

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

There is a function already in categories.php that counts products in each category that will not place any extra burden on the system with more joined queries - if the count is 0 then don't display the link.

 

Find:

  while ($categories = tep_db_fetch_array($categories_query))  {
   if ($level{$categories['parent_id']} == "") { $level{$categories['parent_id']} = 0; }
   $level{$categories['categories_id']} = $level{$categories['parent_id']} + 1;

// Add category link to $categories_string
   for ($a=1; $a<$level{$categories['categories_id']}; $a++) {
     $categories_string .= "  ";
   }

 

Change to:

  while ($categories = tep_db_fetch_array($categories_query))  {
   if ($level{$categories['parent_id']} == "") { $level{$categories['parent_id']} = 0; }
   $level{$categories['categories_id']} = $level{$categories['parent_id']} + 1;

     $products_in_category = tep_count_products_in_category($categories['categories_id']);
     if ($products_in_category > 0) {

// Add category link to $categories_string
   for ($a=1; $a<$level{$categories['categories_id']}; $a++) {
     $categories_string .= "  ";
   }

 

 

Find:

      else { tep_show_category($categories['categories_id'], $cPath_new, $COLLAPSABLE); }

   }

 }

}
?>

 

Change to:

      else { tep_show_category($categories['categories_id'], $cPath_new, $COLLAPSABLE); }

   }

 }

}

}
?>

 

I just tested it and it works like a charm :D

Link to comment
Share on other sites

Hi tony

 

Good catch - just wondering if this also works if you don't show the product count ?

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

  • 9 months later...

hello, sorry to revive an old thread, but this may just be the answer to my prayers. I'm trying to run a sub-store with a manufacturer filter applied across the entire store. Anybody got a clue how I could add a manufacturer requirement into this category count, and therefore not show a category if no products by the relevant manufacturer in it??

 

Also, just for the record, I have been through both my includes/boxes/categories.php and the file which comes with the stock download, and I cant find the portion of code above - any ideas where this is?

 

Thanks in advance!

Please note - if I have suggested a contrib above, it doesnt mean it will work! Most of the contribs are not ones I've used, but may be useful for your particular problem....

Have you tried a refined search? Chances are your problem has already been dealt with elsewhere on the forums.....

if (stumped == true) {

return(square_one($start_over)

} else {

$random_query = tep_fetch_answer($forum_query)

}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...