[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path Zen Cart 源代码 functions_categories.php
//// // Return the number of products in a category // TABLES: products, products_to_categories, categories function zen_count_products_in_category($category_id, $include_inactive = false) { global $db; $products_count = 0; if ($include_inactive == true) { $products_query = "select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$category_id . "'";
} else { $products_query = "select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p.products_status = '1' and p2c.categories_id = '" . (int)$category_id . "'";
if ($child_categories->RecordCount() > 0) { while (!$child_categories->EOF) { $products_count += zen_count_products_in_category($child_categories->fields['categories_id'], $include_inactive); $child_categories->MoveNext(); } }
return $products_count; }
//// // Return true if the category has subcategories // TABLES: categories function zen_has_category_subcategories($category_id) { global $db; $child_category_query = "select count(*) as count from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$category_id . "'";
//// function zen_get_categories($categories_array = '', $parent_id = '0', $indent = '', $status_setting = '') { global $db;
if (!is_array($categories_array)) $categories_array = array();
// show based on status if ($status_setting != '') { $zc_status = " c.categories_status='" . (int)$status_setting . "' and "; } else { $zc_status = ''; }
$categories_query = "select c.categories_id, cd.categories_name, c.categories_status from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where " . $zc_status . " parent_id = '" . (int)$parent_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$_SESSION['languages_id'] . "' order by sort_order, cd.categories_name";
while (!$subcategories->EOF) { $subcategories_array[sizeof($subcategories_array)] = $subcategories->fields['categories_id']; if ($subcategories->fields['categories_id'] != $parent_id) { zen_get_subcategories($subcategories_array, $subcategories->fields['categories_id']); } $subcategories->MoveNext(); } }
//// // Recursively go through the categories and retreive all parent categories IDs // TABLES: categories function zen_get_parent_categories(&$categories, $categories_id) { global $db; $parent_categories_query = "select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$categories_id . "'";
while (!$parent_categories->EOF) { if ($parent_categories->fields['parent_id'] == 0) return true; $categories[sizeof($categories)] = $parent_categories->fields['parent_id']; if ($parent_categories->fields['parent_id'] != $categories_id) { zen_get_parent_categories($categories, $parent_categories->fields['parent_id']); } $parent_categories->MoveNext(); } }
//// // Construct a category path to the product // TABLES: products_to_categories function zen_get_product_path($products_id) { global $db; $cPath = '';
$category_query = "select p.products_id, p.master_categories_id from " . TABLE_PRODUCTS . " p where p.products_id = '" . (int)$products_id . "' limit 1";
if (zen_not_null($cPath)) $cPath .= '_'; $cPath .= $category->fields['master_categories_id']; }
return $cPath; }
//// // Parse and secure the cPath parameter values function zen_parse_category_path($cPath) { // make sure the category IDs are integers $cPath_array = array_map('zen_string_to_int', explode('_', $cPath));
// make sure no duplicate category IDs exist which could lock the server in a loop $tmp_array = array(); $n = sizeof($cPath_array); for ($i=0; $i<$n; $i++) { if (!in_array($cPath_array[$i], $tmp_array)) { $tmp_array[] = $cPath_array[$i]; } }
return $tmp_array; }
function zen_product_in_category($product_id, $cat_id) { global $db; $in_cat=false; $category_query_raw = "select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$product_id . "'";
$category = $db->Execute($category_query_raw);
while (!$category->EOF) { if ($category->fields['categories_id'] == $cat_id) $in_cat = true; if (!$in_cat) { $parent_categories_query = "select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . $category->fields['categories_id'] . "'";
//// // products with name, model and price pulldown function zen_draw_products_pull_down($name, $parameters = '', $exclude = '') { global $currencies, $db;
if ($exclude == '') { $exclude = array(); }
$select_string = '<select name="' . $name . '"';
if ($parameters) { $select_string .= ' ' . $parameters; }
$select_string .= '>';
$products = $db->Execute("select p.products_id, pd.products_name, p.products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and pd.language_id = '" . (int)$_SESSION['languages_id'] . "' order by products_name");
//// // categories pulldown with products with attributes function zen_draw_products_pull_down_categories_attributes($name, $parameters = '', $exclude = '') { global $db, $currencies;
if ($exclude == '') { $exclude = array(); }
$select_string = '<select name="' . $name . '"';
if ($parameters) { $select_string .= ' ' . $parameters; }
$select_string .= '>';
$categories = $db->Execute("select distinct c.categories_id, cd.categories_name " ." from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_PRODUCTS_TO_CATEGORIES . " ptoc, " . TABLE_PRODUCTS_ATTRIBUTES . " pa " ." where pa.products_id= ptoc.products_id and ptoc.categories_id= c.categories_id and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$_SESSION['languages_id'] . "' order by categories_name");
//// look up parent categories name function zen_get_categories_parent_name($categories_id) { global $db;
$lookup_query = "select parent_id from " . TABLE_CATEGORIES . " where categories_id='" . (int)$categories_id . "'"; $lookup = $db->Execute($lookup_query);
$lookup_query = "select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id='" . (int)$lookup->fields['parent_id'] . "' and language_id= " . $_SESSION['languages_id']; $lookup = $db->Execute($lookup_query);
return $lookup->fields['categories_name']; }
//// // Get all products_id in a Category and its SubCategories // use as: // $my_products_id_list = array(); // $my_products_id_list = zen_get_categories_products_list($categories_id) function zen_get_categories_products_list($categories_id, $include_deactivated = false, $include_child = true, $parent_category = '0', $display_limit = '') { global $db; global $categories_products_id_list; $childCatID = str_replace('_', '', substr($categories_id, strrpos($categories_id, '_')));