Re: NOT WORKING IN V1.5.5f Re: How to hide categories with no active products
Unfortunately, the code changes did not hide the categories with no products. When the switch is set to 1, I can still follow the menu to:
"There are no products to list in this category."
I suppose I need to hack some menu code to make that happen...
Re: NOT WORKING IN V1.5.5f Re: How to hide categories with no active products
Quote:
Originally Posted by
net3431
Unfortunately, the code changes did not hide the categories with no products. When the switch is set to 1, I can still follow the menu to:
"There are no products to list in this category."
I suppose I need to hack some menu code to make that happen...
With absence of detail, not sure which code chnages have been applied. The recommended code changes for ZC 1.5.5 were provided by the all wonderful Ajeh back in this post: https://www.zen-cart.com/showthread....47#post1265047
Perhaps some post after offered further guidance, I did not look beyond that in my own short sightedness.
Re: NOT WORKING IN V1.5.5f Re: How to hide categories with no active products
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.