-
How to hide categories with no active products?
I have several categories that have zero active products. Is there some setting in Zen Cart that will automatically hide any categories that have 0 active products or will this require custom code?
I saw a setting that says Categories with 0 Products Status, but this doesn't have any effect.
I would disable to the categories manually, but this keeps changing depending on the items in stock, so this is very difficult.
Thanks for any info on this.
-
Re: How to hide categories with no active products
In think that what this mod does
http://www.zen-cart.com/index.php?ma...roducts_id=286
Categories with 0 Products Status just hides the product count for that category so you don't have categories in three with (0)
-
Re: How to hide categories with no active products
According to the description for that mod, it seems to hide them when the customer chooses to hide them via a selection on a side box.
I'll download that and see how the code works, maybe I can reuse code to make it work the way I want it.
-
Re: How to hide categories with no active products
I'm in the same boat...the link above to solve this issue is for v1.3. I have version 1.5.1.
I've been trying for weeks to figure out how to hide all subcategories where category counts are 0 of ### active. I have searched in the developers tool kit and looked in the database for anything related to category counts but have came up empty.
I know you can click on the green/red buttons to change the categories. I'm looking for a way to automate it. I have over 7000 products in my store and it's very time consuming to manually go through each category/subcategory to find all of the categories that are 0 of ### active and deactivate them. I don't want to leave them on because that will not give the shopper a very good experience when they click on a category and nothing is there.
I have posted this issue here http://www.zen-cart.com/showthread.p...s-are-inactive but it's not a very active feed.
Where are category counts calculated and stored so that they will display on the admin/categories pages? That is the key I need to finish building my sql statement for taking care of this issue.
If anyone can help, I'd appreciate it.
-
Re: How to hide categories with no active products
Did you try Configuration->Layout Settings->Categories with 0 Products Status ... and set it to 0 (off)?
-
Re: How to hide categories with no active products
You could customize the code, using your templates and overrides, for the file:
/includes/templates/templates_default/sideboxes/tpl_categories.php
and add the code in RED:
Code:
if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1) or $box_categories_array[$i]['count'] == 0) {
// skip if this is for the document box (==3)
// skip if this category has no active products
} else {
See if that accomplishes what you are attempting ...
-
Re: How to hide categories with no active products
I did try that but it has no effect.
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
mikeel100
I did try that but it has no effect.
Did you try Configuration->Layout Settings->Categories with 0 Products Status ... and set it to 0 (off)?
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
Ajeh
You could customize the code, using your templates and overrides, for the file:
/includes/templates/templates_default/sideboxes/tpl_categories.php
and add the code in
RED:
Code:
if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1) or $box_categories_array[$i]['count'] == 0) {
// skip if this is for the document box (==3)
// skip if this category has no active products
} else {
See if that accomplishes what you are attempting ...
That made all of my categories disappear...here is the code that I modified with your suggestion.
if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1) or $box_categories_array[$i]['count'] == 0) {
// skip if this is for the document box (==3)
// skip if this category has no active products MIKE
} else {
$content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1) or $box_categories_array[$i]['count'] == 0) {
// skip if this is for the document box (==3)
// skip if this category has no active products MIKE
WHAT DO I NEED TO COMMENT OUT BELOW TO MAKE IT SKIP } else {
$content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
lat9
Did you try Configuration->Layout Settings->Categories with 0 Products Status ... and set it to 0 (off)?
It was already set to zero...besides, that is for category counts..."Show Category Count for 0 Products?"
Thanks though.
-
Re: How to hide categories with no active products
Just so you know, I did copy /includes/templates/templates_default/sideboxes/tpl_categories.php
and place it in my customized folder... /includes/templates/MY_FILES/sideboxes/tpl_categories.php
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
mikeel100
Did you try Configuration->Layout Settings->Categories with 0 Products Status ... and set it to 0 (off)?
Yes, I'm talking to myself again...LOL. Need a break.
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
mikeel100
That made all of my categories disappear...here is the code that I modified with your suggestion.
if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1) or $box_categories_array[$i]['count'] == 0) {
// skip if this is for the document box (==3)
// skip if this category has no active products MIKE
} else {
$content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1) or $box_categories_array[$i]['count'] == 0) {
// skip if this is for the document box (==3)
// skip if this category has no active products MIKE
WHAT DO I NEED TO COMMENT OUT BELOW TO MAKE IT SKIP } else {
$content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
Ignore the double code above...I must have double pasted when I was replying. The code in my file is not doubled like it is above...
-
Re: How to hide categories with no active products
I forgot ... you probably have set this to false:
Quote:
Show Category Counts
Count recursively how many products are in each category
Turn that to true ...
Now, starting with a clean:
/includes/templates/templates_default/sideboxes/tpl_categories.php
using your templates and overrides make the following changes in RED:
Code:
if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1 or $box_categories_array[$i]['count'] == 0)) {
// skip if this is for the document box (==3)
} else {
$content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
Then change the code:
Code:
if (false && SHOW_COUNTS == 'true') {
if ((CATEGORIES_COUNT_ZERO == '1' and $box_categories_array[$i]['count'] == 0) or $box_categories_array[$i]['count'] >= 1) {
$content .= CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX;
}
}
So while you say show the counts in configuration ... you will not show the counts but will still gather the counts so that categories with 0 Products will not show ...
Does this work better for you?
-
Re: How to hide categories with no active products
Where, in zencart, are the calculations done for making the, ## of ## active, display next to the green/red buttons in admin/categories? That is the info I need to make a simple MySQL code work for this issue.
I've posted the post below at stackoverflow to try and help find a solution as well...http://stackoverflow.com/questions/1...egory-are-zero
First off, let me say I am a NOVICE MySQL programmer. I appreciate any help I can get.
I am trying to update a record value in one table where the count of records in a separate table are equal to the count of records in another table where a certain criteria is met.
In real language: Within a specific category, if all of the products_status, in table products, are set to 0 (not active), then I want to set the category_status, in table category, to 0 (hidden).
I'll explain my thought process after I give you a little background info.
The relevant parts of my categories table are: categories_id (unique and autoincremented) categories_status (0 or 1) parent_id
The relevant parts of my products table are: products_id (autoincremented) products_status (O or 1) master_categories_id (I believe it is linked to the categories_id column n the categories table)
The products_to_categories table has two columns: products_id categories_id
Now, this is what I am attempting:
1. Go to the first record of categories.categories_id and set that as a variable (CategorySearchID).
2. Go to products.master_categories_id and count the number of records that match the CategorySearchID and set that to a variable (CategorySearchIDCount). This gives the total number of products in that CategorySearchID.
3. Go to products.products_status and count all records that have a product_status of 0 where the CategorySearchID is a match.
4. Compare the counts in step 2 and 3. If they are equal, the categories.category_status for the current CategorySearchId will be set to 0 (hidden).
5. Finally, I need a loop that will search through all categories.category_id (CategorySearchID) and do the count comparisons and status updates in steps 2, 3 and 4.
I have tried dozens of combinations of the following code but keep getting errors. I can get some of the individual element of the code to work but I can't seem to tie them all together.
For example:
UPDATE DATABASE.categories SET categories_status = 0
Sets all category_status' to 0 successfully
SELECT COUNT(products_id) FROM products WHERE products_status=0
Finds all of the products_status' set to 0 and returns the number in a temporary table.
AND parent_id != 0;
Prevents top level categories from being set to hidden
I'm not going to bore you with all of the combinations I've tried.
Again, I really would appreciate any help!
Mike
-
Re: How to hide categories with no active products
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?
-
Re: How to hide categories with no active products
Your a life saver and a genius Ajeh! Thanks!
I believe this will work! No need to manually change CATEGORY buttons from green to red now!
It's not affecting searches neither!
I can sleep tonight...LOL.
I'll post this answer into the other threads I ran across where nobody found a solution to.
-
Re: How to hide categories with no active products
Thanks for the update that this did work for you ... :smile:
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
Ajeh
Thanks for the update that this did work for you ... :smile:
No, thank you! I have ran across so many topics where people left me hanging for an answer...I didn't want to do that to anyone else. It's very frustrating. :)
-
Re: How to hide categories with no active products
Always a pleasure ... remember the Zen Cart Team when you are rich and famous! :cool:
-
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.
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
Ajeh
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 ...
Actually, I want to hide subcategories where all products are inactive and subcategories where no products are in them.
Didn't work...it hid the empty categories but it also hid some categories with products active. It also left random blank areas where categories should be.
The end of my categories_tab page code looks different than yours. . ' ' . $countContentProduct is missing right before </a>.
PHP Code:
$categories->fields['categories_name'] . '</a>');
$col ++;
if ($col > (MAX_DISPLAY_CATEGORIES_PER_ROW -1)) {
$col = 0;
$row ++;
}
$categories->MoveNext();
}
}
I don't know if that has anything to do with it since I'm no guru on this code.
Thanks again.
-
Re: How to hide categories with no active products
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
mikeel100
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.
This code will only hide the BOTTOM LEVEL SUBCATEGORIES.
-
Re: How to hide categories with no active products
Sorry, I ended the IF incorrectly ...
Try this code in RED:
Code:
// bof: hide empty categories
if (zen_count_products_in_category($categories->fields['categories_id']) == 0) {
// skip empty category
echo 'Skipped empty category: ' . $categories->fields['categories_name'] . '<br>';
} 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>');
$col ++;
if ($col > (MAX_DISPLAY_CATEGORIES_PER_ROW -1)) {
$col = 0;
$row ++;
}
}
// eof: hide empty categories
$categories->MoveNext();
}
}
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
Ajeh
Sorry, I ended the IF incorrectly ...
Try this code in
RED:
Code:
// bof: hide empty categories
if (zen_count_products_in_category($categories->fields['categories_id']) == 0) {
// skip empty category
echo 'Skipped empty category: ' . $categories->fields['categories_name'] . '<br>';
} 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>');
$col ++;
if ($col > (MAX_DISPLAY_CATEGORIES_PER_ROW -1)) {
$col = 0;
$row ++;
}
}
// eof: hide empty categories
$categories->MoveNext();
}
}
You are a genius and I really appreciate the help!
I like the echo trick to show which categories got hidden!
-
Re: How to hide categories with no active products
Just comment that out after testing ...
Thanks for the update that this is working for you ...
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
Ajeh
Just comment that out after testing ...
Thanks for the update that this is working for you ...
Comment what out?
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
mikeel100
Comment what out?
The echo statement..
-
Re: How to hide categories with no active products
Doh, yes, I had already done that. Thanks.
-
Re: How to hide categories with no active products
This does work in 1.5.3 ... please consider adding this to the next upgrade package.
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
mikeel100
This does work in 1.5.3 ... please consider adding this to the next upgrade package.
If it were to be added to the codebase, it should be an admin configurable item..
-
Re: How to hide categories with no active products
Why? What is the point of showing empty categories? There are already too many "configurable options" in the admin area...just sayin'
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
mikeel100
Why? What is the point of showing empty categories? There are already too many "configurable options" in the admin area...just sayin'
The absence of a product in a category doesn't mean that the category (and with modification all of the parent categories) is useless or doesn't provide value for the store. While generally not suggested to have a "coming soon" type display of information, I'm sure that over the years that store owners have found creative ways to use categories that do not have products for various things. As well, as pointed out the offered code only addresses the last category not having products. It doesn't address all categories between the top and that last categoy. Not that it couldn't be modified to do so, but even that additional code would be recommended to be an admin configurable option.
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
mikeel100
Why? What is the point of showing empty categories? There are already too many "configurable options" in the admin area...just sayin'
Because just because YOU don't want to show empty categories doesn't mean that ALL STORES should be FORCED to have the SAME option because YOU don't agree with or understand it.. (hence WHY it should be an admin configurable option). Plus as mc12345678 pointed out this isn't a complete solution to cover ALL variables of hiding empty categories..
As for WHY would you want empty categories??? There are MANY business reasons for this and I am NOT going to list them all and do the follow-up "back and forth" discussion on them and take this thread WAAAAAY off topic.. You may think there are too many admin options, but that simply makes Zen Cart FLEXIBLE and not some silly "one size fits all" solution. Additionally CHOICES for these options keeps novices from making core code changes they may not remember they made when upgrading their site.. Frankly I'm glad Zen Cart offers configuration options that allow you more than ONE option where it's CLEAR there should be choices.. Otherwise this forum will be filled even more with those "how can I do this?" posts.
Quote:
Originally Posted by
mc12345678
The absence of a product in a category doesn't mean that the category (and with modification all of the parent categories) is useless or doesn't provide value for the store. While generally not suggested to have a "coming soon" type display of information, I'm sure that over the years that store owners have found creative ways to use categories that do not have products for various things. As well, as pointed out the offered code only addresses the last category not having products. It doesn't address all categories between the top and that last categoy. Not that it couldn't be modified to do so, but even that additional code would be recommended to be an admin configurable option.
**nods in agreement** :yes:
-
Re: How to hide categories with no active products
This is being worked into v16 as v154 is close to release and this cannot be added ...
There are 4 files that should be addressed:
/includes/templates/template_default/sideboxes/tpl_categories.php
/includes/modules/category_row.php
/includes/modules/categories_tabs.php
/includes/classes/site_map.php
to manage hiding the categories when either they are empty or when they only contain Products with products_status = 0 ...
This would be controlled by an on/off switch in the Admin to allow for those who want this feature and those who do not ...
When I have time, I will try to post the changes needed but I need to compare them to v154 vs v151 to see what the differences, if any, may be ...
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
Ajeh
This is being worked into v16 as v154 is close to release and this cannot be added ...
There are 4 files that should be addressed:
/includes/templates/template_default/sideboxes/tpl_categories.php
/includes/modules/category_row.php
/includes/modules/categories_tabs.php
/includes/classes/site_map.php
to manage hiding the categories when either they are empty or when they only contain Products with products_status = 0 ...
This would be controlled by an on/off switch in the Admin to allow for those who want this feature and those who do not ...
When I have time, I will try to post the changes needed but I need to compare them to v154 vs v151 to see what the differences, if any, may be ...
Awesome news Ajeh!!! and kudos for making is CHOICE for shopowners.. (not a fan of "one size fits all" features) I do have a few clients who want this (hence why I subscribed to this thread to begin with) so it will be nice to see this make it's way into the core..
-
Re: How to hide categories with no active products
If you guys want to test this the changes are marked in RED:
/includes/templates/template_default/sideboxes/tpl_categories.php
Code:
if ((CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && $box_categories_array[$i]['count'] == 0) || zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
// skip if this is for the document box (==3)
// skip empty or status off categories
} else {
$content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
if ($box_categories_array[$i]['current']) {
if ($box_categories_array[$i]['has_sub_cat']) {
/includes/modules/categories_tabs.php
Code:
// create link to top level category
if (CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && zen_count_products_in_category((int)$categories_tab->fields['categories_id']) == 0) {
// skip empty or status off categories
} else {
$links_list[] = '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . (int)$categories_tab->fields['categories_id']) . '">' . $categories_tab_current . '</a> ';
}
$categories_tab->MoveNext();
/includes/modules/category_row.php
Code:
if (CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && zen_count_products_in_category((int)$categories->fields['categories_id']) == 0) {
// skip empty or status off categories
} 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'] . '</a>');
$col ++;
if ($col > (MAX_DISPLAY_CATEGORIES_PER_ROW -1)) {
$col = 0;
$row ++;
}
}
$categories->MoveNext();
/includes/classes/site_map.php
Code:
$categories = $db->Execute($categories_query);
while (!$categories->EOF) {
if (CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && zen_count_products_in_category((int)$categories->fields['categories_id']) == 0) {
// skip empty or status off categories
} else {
$this->data[$categories->fields['parent_id']][$categories->fields['categories_id']] = array('name' => $categories->fields['categories_name'], 'count' => 0);
}
$categories->MoveNext();
}
}
Code:
if (isset($this->data[$parent_id])) {
foreach ($this->data[$parent_id] as $category_id => $category) {
if (CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && zen_count_products_in_category((int)$categories->fields['categories_id']) == 0) {
// skip empty or status off categories
continue;
}
$category_link = $parent_link . $category_id;
$result .= $this->child_start_string;
if (isset($this->data[$category_id])) {
Then add the switch to the configuration table via the Tools ... Install SQL Patches ...
Code:
INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Categories with Inactive Products Status', 'CATEGORIES_PRODUCTS_INACTIVE_HIDE', '0', 'Hide Categories with Inactive Products?<br />0= off<br />1= on', 19, 30, 'zen_cfg_select_option(array(\'0\', \'1\'), ', now());
Setting this new setting in the Configuration ... Layout Settings ... for Categories with Inactive Products Status to 0 or OFF will NOT hide the empty Categories or Categories with all Products set to products_status = 0 and setting this to 1 or ON will hide them ...
-
Re: How to hide categories with no active products
It was a legitimate question...not intended to upset anyone. (DivaVocals)
I still do not see the point of showing categories when no active products are available. It is like having an empty cookie jar on the counter...very frustrating to open it up and see nothing in it when you were expecting to.
I was not implying that this be a ONE SIZE FITS ALL program...but I have been programming long enough to know that you can option yourself to death if you are not careful.
I fully appreciate the flexibility of this outstanding program and the people who make it possible! That is why I have followed this program steadily since 1.3.7.
Thanks for the code Ajeh and for appeasing everyone! You have been a tremendous help indoctrinating me into this program. Novice...maybe, but at least I am looking for ways to improve.
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
mikeel100
It was a legitimate question...not intended to upset anyone. (DivaVocals)
I still do not see the point of showing categories when no active products are available. It is like having an empty cookie jar on the counter...very frustrating to open it up and see nothing in it when you were expecting to.
I was not implying that this be a ONE SIZE FITS ALL program...but I have been programming long enough to know that you can option yourself to death if you are not careful.
I fully appreciate the flexibility of this outstanding program and the people who make it possible! That is why I have followed this program steadily since 1.3.7.
Thanks for the code Ajeh and for appeasing everyone! You have been a tremendous help indoctrinating me into this program. Novice...maybe, but at least I am looking for ways to improve.
Not upset.. **SMH** However IMHO this is a place where an option makes sense.. I have clients who have business reasons why they support either option.. glad Ajeh was on the case!
-
Re: How to hide categories with no active products
You guys are welcome ...
While I would consider the loss of spiders not finding the Category when disabled and good Category description can help get the Products spidered ... I can also see the desire for this feature ...
But, to each their own, hence the switch ... :smile:
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
ajeh
you guys are welcome ...
While i would consider the loss of spiders not finding the category when disabled and good category description can help get the products spidered ... I can also see the desire for this feature ...
But, to each their own, hence the switch ... :smile:
exactly!!!!
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
Ajeh
You guys are welcome ...
While I would consider the loss of spiders not finding the Category when disabled and good Category description can help get the Products spidered ... I can also see the desire for this feature ...
But, to each their own, hence the switch ... :smile:
And as provided the switchis currently a simple on/off, it could even be expanded to a multi-level type switch to activate each of the above modifications differently. Though with the number of locations touched I would advise against trying to consider every potentiaal combination of settings as I would aalso guess that some shouldn't be disabled without another...
Anyways, just thinking about how far a "fix" can go. Like it though seems relatively simple. :)
-
Re: How to hide categories with no active products
Made changes as instructed above.
The Categories Sidebox has no categories showing...I think a closing bracket (}) is missing somewhere but not sure. I have 100,000 products in 2300+ categories with 11 top level categories. None are showing...just the Featured, All, New, and Specials Links.
Site Map - I get a 500 server error.
The center box area categories / subcategories appear to be working.
Category Tabs (top of main page) appears to be working.
I triple checked the code to make sure it is exactly as you suggested :-)
-
Re: How to hide categories with no active products
Site Map appears to be working ... did you fix this?
If so, what was your error? :lookaroun
-
Re: How to hide categories with no active products
The second correction to the Site Map file is using $categories_tab->field instead of $categories->field.
Changing it still didn't fix the sitemap issue.
-
Re: How to hide categories with no active products
Good news ... I did that right for v16 ... Bad news ... I wrote that wrong for what I posted as you discovered ... :blink:
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
Ajeh
Good news ... I did that right for v16 ... Bad news ... I wrote that wrong for what I posted as you discovered ... :blink:
I've been experimenting with the sitemap code but can't seem to get it to work. The logic seems like it is all there but apparently, I'm missing something.
I'm not really concerned with the sidebox or CatTab at this point as I have completely disabled all sideboxes and CatTabs...going for a simpler / cleaner look that is a little more user friendly on mobile devices.
So, should that second edit on the sitemap file be $categories or $categories_tab? $categories makes since to me since the query just above it is $categories.
Thanks.
To answer Ajeh's questions: Internal Server Error after waiting for about 2-3 minutes for the sitemap page to load.
-
Re: How to hide categories with no active products
While we are looking at the sitemap file...can you tell me why "All Products" doesn't show up on the sitemap?
-
Re: How to hide categories with no active products
FYI...all of Ajeh's mods mentioned above work in 1.5.5. Tested and confirmed during my upgrade.
-
Re: How to hide categories with no active products
Quote:
if (CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && zen_count_products_in_category((int)$categories->fields['categories_id']) == 0) {
//skip empty or status off categories
continue;
}
FYI...If you remove the second code change(quote above) in the includes/classes/site_map.php file, the sitemap does hide the products without any quantities.
Not sure what Ajeh was trying to accomplish with this other code...may affect something I am totally unaware of.
All of Ajeh's recommended code changes are working in 1.5.5a...sideboxes unknown since I do not use them.
-
Re: How to hide categories with no active products
Has anyone had success w/ this one 1.5.5? I can't seem to get it to work for me...
-
Re: How to hide categories with no active products
Yes it works in 1.5.5d...which mod are you having trouble with? Category Tabs? Subcategories? Sideboxes?
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
wolfderby
Has anyone had success w/ this one 1.5.5? I can't seem to get it to work for me...
Ignore all the code changes except for those on page 5 of this thread...much of it was experimental until we nailed it down.
I just verified that the changes are working in my live shop...1.5.5d. The site map, horizontal menu (css dropdown on my website), and center box subcategories are working. I do not use the sidebox menu, so, let me know if you are using it and I'll open up my test shop to help if needed.
Did you add the option to your admin table layout settings and set it to the correct value?
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
mikeel100
Ignore all the code changes except for those on page 5 of this thread...much of it was experimental until we nailed it down.
I just verified that the changes are working in my live shop...1.5.5d. The site map, horizontal menu (css dropdown on my website), and center box subcategories are working. I do not use the sidebox menu, so, let me know if you are using it and I'll open up my test shop to help if needed.
Did you add the option to your admin table layout settings and set it to the correct value?
Yeah I added the option and set it. I was eager to go live w/ the westminster new template, so I'm setting up a /test site now to experiment w/ it more on the classic template. I switched it late at night to see if the template was the cause, and it didn't seem to be the cause of it not working. I struggled to bring my site up to 1.5.5d from 1.3.9 recently, so it's probably something I did.
-
Re: How to hide categories with no active products
I feel your pain...took me a while to upgrade as well. I tried Westminster a couple of years ago and had to abandon it.
Be careful with the responsive templates...I'm having an awful time with page load speeds when I use the default install in 1.5.5d. The layout is okay but I do not like the performance.
It sounds like you are on the right path. I probably don't need to say this but...after you fresh install your test shop and before installing any other mods, I recommend you copy the classic files to your template system and modify the appropriate files with the suggestions on page 5 of this feed and test them first.
Good luck.
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
mikeel100
I feel your pain...took me a while to upgrade as well. I tried Westminster a couple of years ago and had to abandon it.
Be careful with the responsive templates...I'm having an awful time with page load speeds when I use the default install in 1.5.5d. The layout is okay but I do not like the performance.
It sounds like you are on the right path. I probably don't need to say this but...after you fresh install your test shop and before installing any other mods, I recommend you copy the classic files to your template system and modify the appropriate files with the suggestions on page 5 of this feed and test them first.
Good luck.
There's a plugin (Clone a Template) that will help! Just "clone" the classic template.
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
lat9
There's a plugin (
Clone a Template) that will help! Just "clone" the
classic template.
Thanks for the tip. The link is not working.
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
mikeel100
Thanks for the tip. The link is not working.
That's weird, it worked for me just now.
-
Re: How to hide categories with no active products?
Quote:
Originally Posted by
lat9
That's weird, it worked for me just now.
It is not working with Chrome in my Samsung Android tablet.
I don't know why.
A new tab opens with this "https://www.zen-cart.com/downloads.php?do=file&id=2087" in the address bar but the page never opens???
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
mikeel100
I feel your pain...took me a while to upgrade as well. I tried Westminster a couple of years ago and had to abandon it.
Be careful with the responsive templates...I'm having an awful time with page load speeds when I use the default install in 1.5.5d. The layout is okay but I do not like the performance.
It sounds like you are on the right path. I probably don't need to say this but...after you fresh install your test shop and before installing any other mods, I recommend you copy the classic files to your template system and modify the appropriate files with the suggestions on page 5 of this feed and test them first.
Good luck.
i am not sure why a responsive design template would in fact be slower.... other than the template itself might be poorly coded.... but a responsive design template per se, in my experience, does not slow a site down...
page speed, y-slow and the like are all fine.... they can point you to elements that can make your site faster..... and caching resources definitely helps with a responsive template (or any template for that matter), but...
https://www.webpagetest.org/
really tells a better story (thanks to @rodg)....
in my experience, ZC can slow down due to database lookups, and hosting on fast servers makes a big difference....
and when i say a fast server, i mean a server with SSD drives including hosting of of your database. big difference IMHO....
if you can ssh to your server, you can test the speed of your drives. you are looking for under 1 second when you run the following code:
Code:
time for i in `seq 1 1000`; do
dd bs=4k if=/dev/sda count=1 skip=$(( $RANDOM * 128 )) >/dev/null 2>&1;
done;
and if your disks respond with under 1 second, ensure that your db is hosted on the same server. i have had some shared hosts where they claimed SSD drives, only to host the db on a separate server using HDD.
best.
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
carlwhat
i am not sure why a responsive design template would in fact be slower.... other than the template itself might be poorly coded.... but a responsive design template per se, in my experience, does not slow a site down...
page speed, y-slow and the like are all fine.... they can point you to elements that can make your site faster..... and caching resources definitely helps with a responsive template (or any template for that matter), but...
https://www.webpagetest.org/
really tells a better story (thanks to @rodg)....
in my experience, ZC can slow down due to database lookups, and hosting on fast servers makes a big difference....
and when i say a fast server, i mean a server with SSD drives including hosting of of your database. big difference IMHO....
if you can ssh to your server, you can test the speed of your drives. you are looking for under 1 second when you run the following code:
Code:
time for i in `seq 1 1000`; do
dd bs=4k if=/dev/sda count=1 skip=$(( $RANDOM * 128 )) >/dev/null 2>&1;
done;the
and if your disks respond with under 1 second, ensure that your db is hosted on the same server. i have had some shared hosts where they claimed SSD drives, only to host the db on a separate server using HDD.
best.
Off topic for this thread...but I appreciate the input.
My DB is on the same drive, speed is okay, and I use db cache already...not sure what is happening.
All I know is that when I turn on responsive in every version of ZC since 1.5.0, my page load speeds are unacceptable (4-5 times slower with GoDaddy and Inmotion Hosting).
So, it is, in fact, slower for me. I have reported this in another forum and if I figure out why it is happening, I will update in that forum.
My images are off site, so I thought something in the CSS might be causing it. https://www.webpagetest.org/ verifies the image loads are the issue, but only in Responsive. Images and pages load very fast in Classic...which tells me the problem is with Responsive.
Maybe it will not be an issue when Bootstrap is introduced in 1.6. I'll live with Classic for now.
Thanks.
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
mikeel100
My images are off site, so I thought something in the CSS might be causing it.
Seriously?
Your images are someplace other than your images folder?
Putting them where they belong would certainly be the first way to fix image slowness. Don't know what you have with the responsive but, any image caching would certainly be hampered by having to go offsite for every request. Not to mention problems in https mode.:dontgetit
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
dbltoe
Seriously?
Your images are someplace other than your images folder?
Putting them where they belong would certainly be the first way to fix image slowness. Don't know what you have with the responsive but, any image caching would certainly be hampered by having to go offsite for every request. Not to mention problems in https mode.:dontgetit
What is the subject of this thread-- " How to hide categories with no active products?"
This discussion shouldn't even be happening here...and I did mention that in the previous post. Please stop responding in this thread unless it has to do with the subject of this thread:-)
Speed is not an issue in Classic...even with the images off site. Believe me, I know all about image optimization. I was reluctant to use off-site images but it works fine in Classic...and there are no cache, speed, or https issues. Again, Classic works great but Responsive does not.
-
Re: How to hide categories with no active products
I won't mention what I thought of responding but, I would like to point out that you made a blanket comment in post #65 that could affect many folk's decisions on templates.
Quote:
Be careful with the responsive templates...I'm having an awful time with page load speeds when I use the default install in 1.5.5d. The layout is okay but I do not like the performance.
Like lat9, we have somewhat of an interest in helping with responsive templates. Your comment sent me straight to test sites to see what could be the cause UNTIL... I saw your offsite images comment.
Non-standard practices WILL have an adverse effect on Zen Cart performance. Other things like old mods, wrong PHP, etc. as well. That's why the posting tips are so important. One of those posting tip questions is "In what ways is your site customized or different from a brand new uncustomized install?"
Your statement (without clarification that yours was not a standard install) could very well cause someone to make an unwise decision in template selection or image placement. You might be able to handle it well but, are you willing to tell others that they could do it as well? Speed is not the only concern when images are off site.
The posting tips are there because we are never "in the same boat." Once one letter; one bit of code; one div call is changed, it becomes your cart unlike any other. Always a similar situation but never the same.
I will comment whenever I feel there is something a budding Zenner needs to know, regardless of the topic. Hopefully, it being found on a Google or forum search will help someone in the future.
That's why I'm here.
you?
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
dbltoe
I won't mention what I thought of responding but, I would like to point out that you made a blanket comment in post #65 that could affect many folk's decisions on templates.
Like lat9, we have somewhat of an interest in helping with responsive templates. Your comment sent me straight to test sites to see what could be the cause UNTIL... I saw your offsite images comment.
Non-standard practices WILL have an adverse effect on Zen Cart performance. Other things like old mods, wrong PHP, etc. as well. That's why the posting tips are so important. One of those posting tip questions is "In what ways is your site customized or different from a brand new uncustomized install?"
Your statement (without clarification that yours was not a standard install) could very well cause someone to make an unwise decision in template selection or image placement. You might be able to handle it well but, are you willing to tell others that they could do it as well? Speed is not the only concern when images are off site.
The posting tips are there because we are never "in the same boat." Once one letter; one bit of code; one div call is changed, it becomes your cart unlike any other. Always a similar situation but never the same.
I will comment whenever I feel there is something a budding Zenner needs to know, regardless of the topic. Hopefully, it being found on a Google or forum search will help someone in the future.
That's why I'm here.
you?
I did not mean to be abrasive in my post. I've been hammered a couple of times by the Good Doctor for having off topic conversations...just trying to prevent it from happening again.
I do appreciate your insight.
Let's end the discussion on Responsive Classic speed in this topic.
Later:-)
-
Re: How to hide categories with no active products
Quote:
Originally Posted by
mikeel100
I feel your pain...took me a while to upgrade as well. I tried Westminster a couple of years ago and had to abandon it.
Be careful with the responsive templates...I'm having an awful time with page load speeds when I use the default install in 1.5.5d. The layout is okay but I do not like the performance.
It sounds like you are on the right path. I probably don't need to say this but...after you fresh install your test shop and before installing any other mods, I recommend you copy the classic files to your template system and modify the appropriate files with the suggestions on page 5 of this feed and test them first.
Good luck.
thanks for the advice, I followed it and realized I must have been trying to make these mods too late at night haha.
-
NOT WORKING IN V1.5.5f Re: How to hide categories with no active products
This does not create a switch in layout:
Quote:
Originally Posted by
Ajeh
Then add the switch to the configuration table via the Tools ... Install SQL Patches ...
Code:
INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Categories with Inactive Products Status', 'CATEGORIES_PRODUCTS_INACTIVE_HIDE', '0', 'Hide Categories with Inactive Products?<br />0= off<br />1= on', 19, 30, 'zen_cfg_select_option(array(\'0\', \'1\'), ', now());
Setting this new setting in the Configuration ... Layout Settings ... for Categories with Inactive Products Status to 0 or OFF will NOT hide the empty Categories or Categories with all Products set to products_status = 0 and setting this to 1 or ON will hide them ...
-
Re: NOT WORKING IN V1.5.5f Re: How to hide categories with no active products
Quote:
Originally Posted by
net3431
This does not create a switch in layout:
When you access your admin and select configuration->Layout Settings, what does the rest of your uri show after configuration.php ?
-
Re: NOT WORKING IN V1.5.5f Re: How to hide categories with no active products
-
Re: NOT WORKING IN V1.5.5f Re: How to hide categories with no active products
Son of gun... it's there now.
Categories with Inactive Products Status
Edit
Hide Categories with Inactive Products?
0= off
1= on
-
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.