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.