If you do not want to booger up your Zencart files and keep track of multiple files changing, run this code:
PHP Code:
//HIDE CATEGORIES AND SUBCATEGORIES WITH NO ACTIVE PRODUCTS
$distict_cIDs = $db->execute("select distinct `categories_id` from `" . TABLE_CATEGORIES . "` where `categories_id` not in (select `parent_id` from `" . TABLE_CATEGORIES . "`) ");
foreach ($distict_cIDs as $ids) {
$distinct_cID = $distict_cIDs->fields['categories_id'];
$mcid_to_status_count = $db->execute("SELECT COUNT(`master_categories_id`) AS `NumberOfProducts` FROM `" . TABLE_PRODUCTS . "` WHERE `master_categories_id` = $distinct_cID and `products_status` = 1 ");
$count = $mcid_to_status_count->fields['NumberOfProducts'];
if ($count == 0) {
$db->execute("update " . TABLE_CATEGORIES . " set `categories_status` = 0 where `categories_id` = $distinct_cID ");
}
}
//INCREASE < 3 AS NEEDED...THIS CODE, WITH THE ONE ABOVE WILL TAKE CARE OF 4 CATEGORIES/SUBCATEGORIES DEEP
$i = 0;
while ($i < 3) {
$distict_cIDs = $db->execute("select distinct `categories_id` from `" . TABLE_CATEGORIES . "` where `categories_id` in (select `parent_id` from `" . TABLE_CATEGORIES . "`) ");
foreach ($distict_cIDs as $ids) {
$distinct_cID = $distict_cIDs->fields['categories_id'];
$associated_subcategories_count = $db->execute("SELECT COUNT(`categories_id`) AS `AssociatedSubcategoriesCount` FROM `" . TABLE_CATEGORIES . "` WHERE `parent_id` = $distinct_cID ");
$subcategories_count = $associated_subcategories_count->fields['AssociatedSubcategoriesCount'];
$associated_subcategories_count_status_0 = $db->execute("SELECT COUNT(`categories_id`) AS `SubcategoriesStatus0Count` FROM `" . TABLE_CATEGORIES . "` WHERE `parent_id` = $distinct_cID and `categories_status` = 0 ");
$status_2_count = $associated_subcategories_count_status_0->fields['SubcategoriesStatus0Count'];
if ($subcategories_count == $status_2_count) {
$db->execute("update " . TABLE_CATEGORIES . " set `categories_status` = 0 where `categories_id` = $distinct_cID ");
}
}
$i++;
}
I run it every time I check for supplier updates (twice a day).
Ideally, plug it into the end of the ordering process so that it runs every time an order is completed.
If you are smart enough to turn it into a "watcher class" please do and share with everyone.
Bookmarks