Re: How to hide categories with no active products
Believe me, I will contribute financially if I can ever get people to start buying. I purchased a FB add and I have thousands of hits on the site from 16 states and 10 countries, thousands of likes in FB, but still no orders. Maybe by the shopping season people will remember the site and return for purchases. I'll buy another add just before shopping season and see if that is the ticket. It's a wait and see game from here on out. Thanks again.
Re: How to hide categories with no active products
Quote:
Originally Posted by
Ajeh
In the Class category_tree.php the counts are made and the tree made for the sidebox ...
With only the changes that I posted, for only the tpl_categories.php file, Only Categories that contain Active Products are showing ... NOTE: you need the Category Counts turned on in the settings to know which Categories to show or exclude, but the counts will still be hidden based on the code changes that I posted ...
Have you additional changes that might be causing this to not work for you?
Hi Ajeh,
How do I hide categories, with no active products, in the horizontal/top page menu and subcategories/center page?
Background:
I've upgraded my cart to a responsive plug in...because most clicks are coming from mobile devices.
I switched from using the category box to the horizontal menu across the top and showing subcategories in the center page area.
The fix you gave me for hiding inactive products in the sidebox categories doesn't take care of the horizontal menu and center box subcategories. How do I fix that?
Thanks for your help!
Re: How to hide categories with no active products
See if this will hide the empty categories from the category tabs ...
Edit the file:
/includes/modules/categories_tabs.php
and add the code in RED:
Code:
while (!$categories_tab->EOF) {
// bof: skip empty categories
if (zen_count_products_in_category($categories_tab->fields['categories_id']) == 0) {
// skip display of empty categories
} else {
// currently selected category
if ((int)$cPath == $categories_tab->fields['categories_id']) {
$new_style = 'category-top';
$categories_tab_current = '<span class="category-subs-selected">' . $categories_tab->fields['categories_name'] . '</span>';
} else {
$new_style = 'category-top';
$categories_tab_current = $categories_tab->fields['categories_name'];
}
// create link to top level category
$links_list[] = '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . (int)$categories_tab->fields['categories_id']) . '">' . $categories_tab_current . '</a> ';
}
// eof: skip empty categories
$categories_tab->MoveNext();
}
Re: How to hide categories with no active products
Made changes and saved to my current template. Cleared cache. Empty / non-active categories still showing.
Code:
$links_list = array();
while (!$categories_tab->EOF) {
// bof: skip empty categories ADDED BY MIKE
if (zen_count_products_in_category($categories_tab->fields['categories_id']) == 0) {
// skip display of empty categories
} else {
// currently selected category
if ((int)$cPath == $categories_tab->fields['categories_id']) {
$new_style = 'category-top';
$categories_tab_current = '<span class="category-subs-selected">' . $categories_tab->fields['categories_name'] . '</span>';
} else {
$new_style = 'category-top';
$categories_tab_current = $categories_tab->fields['categories_name'];
}
// create link to top level category
$links_list[] = '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . (int)$categories_tab->fields['categories_id']) . '">' . $categories_tab_current . '</a> ';
}
// eof: skip empty categories } ABOVE THIS LINE ADDED BY MIKE
$categories_tab->MoveNext();
}
Do I need to undo the changes I made earlier in this thread to make this work?
Re: How to hide categories with no active products
Have you an URL to your domain where we can perhaps look at the layout of things?
Re: How to hide categories with no active products
I see what's wrong: Actual code needs to go in place of "// skip display of empty categories". I'll see if I can figure out the code. I use PDO programming with php and mysql. Will that work here?
Re: How to hide categories with no active products
Actually, I used the exact code that I posted, with the comments and no changes, to block the empty categories ... this is why it might help to see your site and know which categories should not be showing in the category tabs ...
Re: How to hide categories with no active products
Quote:
Originally Posted by
Ajeh
Actually, I used the exact code that I posted, with the comments and no changes, to block the empty categories ... this is why it might help to see your site and know which categories should not be showing in the category tabs ...
https://jestcountrystuff.com/index.p...dex&cPath=1563
Camping and Trailer Hitch Hammakas are empty categories.
I tried the code you sent with category counts turned off and on...no joy.
I also tried removing your recommended changes (earlier in this thread)...no joy.
I am using 1.5.1 on Godaddy with Responsive Classic Template, EP4, UPS, dbBackup, Wishlists, and I added Social Share buttons manually. None of those should be messing with categories (I think)...:unsure:
Thanks for your help!
Re: How to hide categories with no active products
It sounds like what you really want to do is not show the Empty Categories in the middle of the page ...
To do that, you can edit the module:
/includes/modules/category_row.php
and add the code in RED:
Code:
// bof: hide empty categories
if (zen_count_products_in_category($categories->fields['categories_id']) == 0) {
// skip empty category
} else {
$list_box_contents[$row][$col] = array('params' => 'class="categoryListBoxContents"' . ' ' . 'style="width:' . $col_width . '%;"',
'text' => '<a href="' . zen_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . zen_image(DIR_WS_IMAGES . $categories->fields['categories_image'], $categories->fields['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '<br />' . $categories->fields['categories_name'] . ' ' . $countContentProduct . '</a>');
}
// bof: hide empty categories
$col ++;
if ($col > (MAX_DISPLAY_CATEGORIES_PER_ROW -1)) {
NOTE: That other code I gave you is not a good solution at all for the Category Tabs, so I would remove it ...
Re: How to hide categories with no active products
I'll give that a shot...
I wrote my own script to use during my catalog update that will take care of my issues.
PHP Code:
<?php
$hostname = "xxxxxxxxxxxxxx";
$username = "xxxxxxxxxxxxx";
$dbname = "xxxxxxxxxxxxxx";
$password = "xxxxxxxxxxxx";
$fail_point = "Connecting to db";
$dbh = new PDO("mysql:host=$hostname;dbname=$dbname;charset=utf8", $username, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try
{
$fail_point = "FIX QUANTITIES EXPONENTIAL AMOUNTS";
$query = ("UPDATE zen_products SET products_quantity = 10 WHERE products_quantity LIKE '%+%'");
$stmt = $dbh->prepare($query);
$stmt->execute();
$fail_point = "RESET QUANTITIES <1 TO 0";
$query = ("UPDATE zen_products SET products_quantity = 0 WHERE products_quantity < 1");
$stmt = $dbh->prepare($query);
$stmt->execute();
$fail_point = "GET QUANTITY TOTALS FROM PRODUCTS TABLE AND ADJUST STATUS";
//THIS HIDES CATEGORIES WITH PRODUCTS IN THEM IN THE BOTTOM CATEGORY LEVEL
foreach ($dbh->query("SELECT DISTINCT parent_id, categories_id FROM zen_categories
WHERE categories_id IN (SELECT master_categories_id FROM zen_products WHERE products_quantity < 1)")as $unique_record)
{
$unique_p_id = $unique_record['parent_id'];
$unique_c_id = $unique_record['categories_id'];
$fail_point = "Counting p2c";
$total = $dbh->query("SELECT SUM(products_quantity) FROM zen_products
WHERE zen_products.master_categories_id = $unique_c_id");
$myQty = $total->fetchColumn();
//echo "Category ID - ".$unique_c_id." Total - ".$myQty."<br>";
$fail_point = "Changing status";
if ($myQty == 0)
{
$query = ("UPDATE zen_categories SET categories_status = 0 WHERE parent_id = $unique_p_id
AND categories_id = $unique_c_id");
$stmt = $dbh->prepare($query);
$stmt->execute();
//echo "Parent ID - ".$unique_p_id." - Status set to 0 <br><br>";
}
else
{
$query = ("UPDATE zen_categories SET categories_status = 1 WHERE parent_id = $unique_p_id
AND categories_id = $unique_c_id ");
$stmt = $dbh->prepare($query);
$stmt->execute();
//echo $unique_p_id." Status set to 1 <br><br>";
}
}
//HIDE EMPTY CATEGORIES
foreach ($dbh->query("SELECT DISTINCT parent_id, categories_id FROM zen_categories
WHERE categories_id NOT IN (SELECT master_categories_id FROM zen_products)")as $unique_record)
{
$unique_p_id = $unique_record['parent_id'];
$unique_c_id = $unique_record['categories_id'];
$test = $dbh->query("SELECT categories_id FROM zen_categories
WHERE $unique_c_id IN (SELECT parent_id FROM zen_categories)");
$subcategories = $test->fetchColumn();
$count = $test->rowCount();
//echo "Category ID - ".$unique_c_id." Subcategories - ".$subcategories."<br>";
$fail_point = "Changing status";
if ($subcategories == 0)
{
$query = ("UPDATE zen_categories SET categories_status = 0 WHERE categories_id = $unique_c_id");
$stmt = $dbh->prepare($query);
$stmt->execute();
//echo "Parent ID - ".$unique_c_id." - Status set to 0 <br><br>";
}
else
{
$query = ("UPDATE zen_categories SET categories_status = 1 WHERE categories_id = $unique_c_id ");
$stmt = $dbh->prepare($query);
$stmt->execute();
//echo $unique_c_id." Status set to 1 <br><br>";
}
}
//HIDE UNCATEGORIZED, NUDES, AND ANY OTHER CATEGORIES YOU DO NOT WANT SHOWING...NOT BASED ON QUANTITY
$fail_point = "Hiding other categories";
$query = ("UPDATE zen_categories SET categories_status = 0 WHERE categories_id = 1539 OR categories_id = 1");
$stmt = $dbh->prepare($query);
$stmt->execute();
}
catch (PDOException $e) {
echo "Hiding categories failed to process." . $fail_point . $e->getMessage() . "<br/>";
die();
}
?>
If you see harm in using this instead, let me know.
Thanks.