📄 functions_categories.php
字号:
$parent_categories->MoveNext();
}
}
$category->MoveNext();
}
return $in_cat;
}
function zen_product_in_parent_category($product_id, $cat_id, $parent_cat_id) {
global $db;
//echo $cat_id . '#' . $parent_cat_id;
if ($cat_id == $parent_cat_id) {
$in_cat = true;
} else {
$parent_categories_query = "select parent_id from " . TABLE_CATEGORIES . "
where categories_id = '" . $parent_cat_id . "'";
$parent_categories = $db->Execute($parent_categories_query);
while (!$parent_categories->EOF) {
if ($parent_categories->fields['parent_id'] !=0 && !$incat) {
$in_cat = zen_product_in_parent_category($product_id, $cat_id, $parent_categories->fields['parent_id']);
}
$parent_categories->MoveNext();
}
}
return $in_cat;
}
////
// 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");
while (!$products->EOF) {
if (!in_array($products->fields['products_id'], $exclude)) {
$display_price = zen_get_products_base_price($products->fields['products_id']);
$select_string .= '<option value="' . $products->fields['products_id'] . '">' . $products->fields['products_name'] . ' (' . $currencies->format($display_price) . ')</option>';
}
$products->MoveNext();
}
$select_string .= '</select>';
return $select_string;
}
////
// product pulldown with attributes
function zen_draw_products_pull_down_attributes($name, $parameters = '', $exclude = '') {
global $db, $currencies;
if ($exclude == '') {
$exclude = array();
}
$select_string = '<select name="' . $name . '"';
if ($parameters) {
$select_string .= ' ' . $parameters;
}
$select_string .= '>';
$new_fields=', p.products_model';
$products = $db->Execute("select distinct p.products_id, pd.products_name, p.products_price" . $new_fields ."
from " . TABLE_PRODUCTS . " p, " .
TABLE_PRODUCTS_DESCRIPTION . " pd, " .
TABLE_PRODUCTS_ATTRIBUTES . " pa " ."
where p.products_id= pa.products_id and p.products_id = pd.products_id
and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
order by products_name");
while (!$products->EOF) {
if (!in_array($products->fields['products_id'], $exclude)) {
$display_price = zen_get_products_base_price($products->fields['products_id']);
$select_string .= '<option value="' . $products->fields['products_id'] . '">' . $products->fields['products_name'] . ' (' . TEXT_MODEL . ' ' . $products->fields['products_model'] . ') (' . $currencies->format($display_price) . ')</option>';
}
$products->MoveNext();
}
$select_string .= '</select>';
return $select_string;
}
////
// categories pulldown with products
function zen_draw_products_pull_down_categories($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 " ."
where 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");
while (!$categories->EOF) {
if (!in_array($categories->fields['categories_id'], $exclude)) {
$select_string .= '<option value="' . $categories->fields['categories_id'] . '">' . $categories->fields['categories_name'] . '</option>';
}
$categories->MoveNext();
}
$select_string .= '</select>';
return $select_string;
}
////
// 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");
while (!$categories->EOF) {
if (!in_array($categories->fields['categories_id'], $exclude)) {
$select_string .= '<option value="' . $categories->fields['categories_id'] . '">' . $categories->fields['categories_name'] . '</option>';
}
$categories->MoveNext();
}
$select_string .= '</select>';
return $select_string;
}
////
// look up categories product_type
function zen_get_product_types_to_category($lookup) {
global $db;
$lookup = str_replace('cPath=','',$lookup);
$sql = "select product_type_id from " . TABLE_PRODUCT_TYPES_TO_CATEGORY . " where category_id='" . $lookup . "'";
$look_up = $db->Execute($sql);
if ($look_up->RecordCount() > 0) {
return $look_up->fields['product_type_id'];
} else {
return false;
}
}
//// 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='" . $categories_id . "'";
$lookup = $db->Execute($lookup_query);
$lookup_query = "select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id='" . $lookup->fields['parent_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) {
global $db;
global $categories_products_id_list;
if ($include_deactivated) {
$products = $db->Execute("select p.products_id
from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c
where p.products_id = p2c.products_id
and p2c.categories_id = '" . (int)$categories_id . "'");
} else {
$products = $db->Execute("select p.products_id
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)$categories_id . "'");
}
while (!$products->EOF) {
// categories_products_id_list keeps resetting when category changes ...
// echo 'Products ID: ' . $products->fields['products_id'] . '<br>';
$categories_products_id_list[] = $products->fields['products_id'];
$products->MoveNext();
}
if ($include_child) {
$childs = $db->Execute("select categories_id from " . TABLE_CATEGORIES . "
where parent_id = '" . (int)$categories_id . "'");
if ($childs->RecordCount() > 0 ) {
while (!$childs->EOF) {
zen_get_categories_products_list($childs->fields['categories_id'], $include_deactivated);
$childs->MoveNext();
}
}
}
$products_id_listing = $categories_products_id_list;
return $products_id_listing;
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -