Totally Zenned
- Join Date:
- Aug 2007
- Location:
- Gijón, Asturias, Spain
- Posts:
- 2,866
- Plugin Contributions:
- 7
products master_category_id = 0
I have come across this a few times over the years.
Of course it should never happen and most likely it is due to something I have done or some mod I have used.
Nonetheless there are a few threads mentioning this and for those with nothing better to do, a quick sort of the products table in phpmyadmin on master_categories_id may be of academic interest to see if you have any products with this problem.
In order to spot this when it happens and identify the action that causes it, I have stuck this in the admin/includes/header.php.
It may be of use to others who find they have some products with a missing master category and would like to know why.
"Caveat Emptor" as always/on a development server only etc...
//steve check that master_categories_id !=0
$master_categories_bad_sql = "SELECT products_id, products_model FROM " . TABLE_PRODUCTS . " WHERE master_categories_id = 0";
$master_categories_bad = $db->Execute($master_categories_bad_sql);
if ($master_categories_bad->count() > 0) {
foreach ($master_categories_bad as $product_row) {
$categories_linked_sql = "SELECT categories_id FROM " . TABLE_PRODUCTS_TO_CATEGORIES . " WHERE products_id = " . $product_row['products_id'];
$categories_linked = $db->Execute($categories_linked_sql);
$category_urls = '';
$cat_count = 1;
foreach ($categories_linked as $category_row) {
$category_linked_name = zen_output_generated_category_path($category_row['categories_id']);
$category_linked_path = implode("_", array_reverse(explode("_", zen_get_generated_category_path_ids
($category_row['categories_id']))));
$category_urls .= '<br />' . $cat_count . ' <a href="categories.php?cPath=' . $category_linked_path . '" target="_blank" title="Open Category in a new tab">' . $category_linked_name . '</a>';
$cat_count++;
}
$master_category_bad_message = '<b>' . $product_row['products_id'] . ' ' . $product_row['products_model'] . '</b>' . $category_urls;
$messageStack->add('Master Categories Id=0 for: ' . $master_category_bad_message, 'error');
}
}
//eof
// display alerts/error messages, if any