zen_get_categories_name_from_product($product_id)
该函数主要通过商品的ID返回该商品所在目录的名字。其实现方式是先从商品表中找到该商品对应的目录ID,然后从目录描述表中找到该目录ID的名字。
主要查询了 products,categories_description 表。在includes/database_tables.php中定义:
define('TABLE_PRODUCTS', DB_PREFIX . 'products');
define('TABLE_CATEGORIES_DESCRIPTION', DB_PREFIX . 'categories_description');
函数源代码:
- function zen_get_categories_name_from_product($product_id) {
- global $db;
- // $check_products_category= $db->Execute("select products_id, categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id='" . $product_id . "' limit 1");
- $check_products_category = $db->Execute("select products_id, master_categories_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");
- $the_categories_name= $db->Execute("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id= '" . $check_products_category->fields['master_categories_id'] . "' and language_id= '" . $_SESSION['languages_id'] . "'");
- return $the_categories_name->fields['categories_name'];
- }
zencart函数zencart-API商品目录