In the product table, a product has a master category id.
In the products_to_categories table, this same category id must exist + (optionally) other category ids that are the linked categories.
Sounds like the product master category id is missing from the products_to_categories table.
This could have arisen from a move/change to that product + a bug in the code, or an import that did not work 100%.
I have had this in the past and added a check in the admin header for this.
If you want to do that, open admin\includes\header.php IN YOUR DEVELOPMENT/TEST SERVER
and find
Code:
} // hide when other language dropdown is used
// display alerts/error messages, if any
and add this in between:
Code:
} // hide when other language dropdown is used
//steve check for zero entry in P2C table
$categories_id_zero = $db->Execute("SELECT products_id FROM " . TABLE_PRODUCTS_TO_CATEGORIES . " WHERE categories_id = 0");
if ($categories_id_zero->count() > 0) {
define('ERROR_PRODUCT_P2C_CATEGORY_ZERO', '%s had category_id=0 in table "' . TABLE_PRODUCTS_TO_CATEGORIES . '". This entry has been deleted.');
foreach ($categories_id_zero as $category_id_zero) {
$db->Execute("DELETE FROM " . TABLE_PRODUCTS_TO_CATEGORIES . " WHERE products_id = " . (int)$category_id_zero['products_id'] . " AND categories_id = 0");
$messageStack->add(sprintf(ERROR_PRODUCT_P2C_CATEGORY_ZERO,
(zen_get_products_model($category_id_zero['products_id']) !== '' ? zen_get_products_model($category_id_zero['products_id']) . ' - ' : '') . '"'
. zen_get_products_name($category_id_zero['products_id']) . '"', 'error'));
}
}
//steve check for master_category in table products_to_categories
//if ($current_page == 'index.php') {
$products_master_category_check_sql = "SELECT p.products_id, master_categories_id, products_model, products_name
FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
WHERE master_categories_id NOT IN
(SELECT categories_id FROM " . TABLE_PRODUCTS_TO_CATEGORIES . " ptc WHERE ptc.products_id = p.products_id)
AND pd.products_id = p.products_id
AND pd.language_id = " . (int)$_SESSION['languages_id'];
$products_master_category_check = $db->Execute($products_master_category_check_sql);
if ($products_master_category_check->count() > 0) {
define('ERROR_MASTER_CATEGORY_MISSING_P2C', '%s: master_category_id entry not found in table "' . TABLE_PRODUCTS_TO_CATEGORIES . '".');
define('MASTER_CATEGORY_INSERT_P2C', '%1$s: master_category_id (#%2$u - %3$s) has been automatically added to table "' . TABLE_PRODUCTS_TO_CATEGORIES . '".');
foreach ($products_master_category_check as $product_row) {
$product = ($product_row['products_model'] !== '' ? $product_row['products_model'] . ' - ' : '') . $product_row['products_name'] . ' (#' . $product_row['products_id'] . ')';
$messageStack->add(sprintf(ERROR_MASTER_CATEGORY_MISSING_P2C, $product), 'error');
$db->Execute("INSERT INTO " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id)
VALUES (" . (int)$product_row['products_id'] . ", " . (int)$products_master_category_check->fields['master_categories_id'] . ")");
// reset products_price_sorter for searches etc.
zen_update_products_price_sorter($product_row['products_id']);
zen_record_admin_activity($product . ' master_category_id auto-added to ' . TABLE_PRODUCTS_TO_CATEGORIES, 'info');
$messageStack->add(sprintf(MASTER_CATEGORY_INSERT_P2C, $product, $products_master_category_check->fields['master_categories_id'],
zen_output_generated_category_path($products_master_category_check->fields['master_categories_id'])), 'success');
}
}
//}
//eof steve
// display alerts/error messages, if any
Bookmarks