论坛风格切换
  • 4572阅读
  • 0回复

获取商品属性信息的函数 [复制链接]

上一主题 下一主题
ben
 

发帖
119
大洋
5222
贡献值
91
只看楼主 正序阅读 使用道具 楼主  发表于: 2011-08-07

zen_get_attributes_sort_order($products_id, $options_id, $options_values_id) 
该函数返回商品的属性排列顺序,输入参数为商品ID,商品属性选项ID,选项值的ID 
主要查询了 products_attributes 表。在includes/database_tables.php中定义: 
define('TABLE_PRODUCTS_ATTRIBUTES', DB_PREFIX . 'products_attributes'); 
函数源代码: 

  1. function zen_get_attributes_sort_order($products_id, $options_id, $options_values_id) {
  2.     global $db;
  3.       $check = $db->Execute("select products_options_sort_order
  4.                              from " . TABLE_PRODUCTS_ATTRIBUTES . "
  5.                              where products_id = '" . (int)$products_id . "'
  6.                              and options_id = '" . (int)$options_id . "'
  7.                              and options_values_id = '" . (int)$options_values_id . "' limit 1");
  8.       return $check->fields['products_options_sort_order'];
  9.   }
 
 
zen_get_attributes_options_sort_order($products_id, $options_id, $options_values_id, $lang_num = '') 
该函数返回商品的属性选项排列顺序,输入参数为商品ID,属性选项ID,选项值ID,语言(默认为空则选用当前所选语言类型ID) 
主要查询了 products_options,products_attributes 表。在includes/database_tables.php中定义: 
  define('TABLE_PRODUCTS_ATTRIBUTES', DB_PREFIX . 'products_attributes'); 
  define('TABLE_PRODUCTS_OPTIONS', DB_PREFIX . 'products_options'); 
函数源代码: 
  1.   function zen_get_attributes_options_sort_order($products_id, $options_id, $options_values_id, $lang_num = '') {
  2.     global $db;
  3.       if ($lang_num == '') $lang_num = (int)$_SESSION['languages_id'];
  4.       $check = $db->Execute("select products_options_sort_order
  5.                              from " . TABLE_PRODUCTS_OPTIONS . "
  6.                              where products_options_id = '" . (int)$options_id . "' and language_id = '" . $lang_num . "' limit 1");
  7.       $check_options_id = $db->Execute("select products_id, options_id, options_values_id, products_options_sort_order
  8.                              from " . TABLE_PRODUCTS_ATTRIBUTES . "
  9.                              where products_id='" . (int)$products_id . "'
  10.                              and options_id='" . (int)$options_id . "'
  11.                              and options_values_id = '" . (int)$options_values_id . "' limit 1");
  12.       return $check->fields['products_options_sort_order'] . '.' . str_pad($check_options_id->fields['products_options_sort_order'],5,'0',STR_PAD_LEFT);
  13.   }
 
 
zen_get_attributes_valid($product_id, $option, $value) 
该函数确定一个商品的属性是否是只读的,如果不是就返回true,否则返回false; 
只读属性为0的话,该属性就会添加到购物车,只读属性为1的话,说明该属性不可以选择添加到购物车做为一个商品的属性。 
输入参数为商品ID,商品属性选项ID,选项值ID。 
主要查询了 products_attributes 表。在includes/database_tables.php中定义: 
define('TABLE_PRODUCTS_ATTRIBUTES', DB_PREFIX . 'products_attributes'); 
函数源代码: 
  1.   function zen_get_attributes_valid($product_id, $option, $value) {
  2.     global $db;
  3. // regular attribute validation
  4.     $check_attributes = $db->Execute("select attributes_display_only, attributes_required from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . (int)$product_id . "' and options_id='" . (int)$option . "' and options_values_id='" . (int)$value . "'");
  5.     $check_valid = true;
  6. // display only cannot be selected
  7.     if ($check_attributes->fields['attributes_display_only'] == '1') {
  8.       $check_valid = false;
  9.     }
  10. // text required validation
  11.     if (preg_match('/^txt_/', $option)) {
  12.       $check_attributes = $db->Execute("select attributes_display_only, attributes_required from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . (int)$product_id . "' and options_id='" . (int)preg_replace('/txt_/', '', $option) . "' and options_values_id='0'");
  13. // text cannot be blank
  14.       if ($check_attributes->fields['attributes_required'] == '1' and empty($value)) {
  15.         $check_valid = false;
  16.       }
  17.     }
  18.     return $check_valid;
  19.   }
 
zen_options_name($options_id) 
该函数通过商品属性选项(比如商品的颜色)的ID来返回该选项的名字,默认返回的语言类型为当前所选语言类型。 
主要查询了 products_options 表。在includes/database_tables.php中定义: 
define('TABLE_PRODUCTS_OPTIONS', DB_PREFIX . 'products_options'); 
函数源代码: 
  1.   function zen_options_name($options_id) {
  2.     global $db;
  3.     $options_id = str_replace('txt_','',$options_id);
  4.     $options_values = $db->Execute("select products_options_name
  5.                                     from " . TABLE_PRODUCTS_OPTIONS . "
  6.                                     where products_options_id = '" . (int)$options_id . "'
  7.                                     and language_id = '" . (int)$_SESSION['languages_id'] . "'");
  8.     return $options_values->fields['products_options_name'];
  9.   }
 
 
zen_values_name($values_id) 
该函数通过商品属性选项的ID返回该选项值的名字。 
主要查询了 products_options_values 表。在includes/database_tables.php中定义: 
define('TABLE_PRODUCTS_OPTIONS_VALUES', DB_PREFIX . 'products_options_values'); 
函数源代码: 
  1.   function zen_values_name($values_id) {
  2.     global $db;
  3.     $values_values = $db->Execute("select products_options_values_name
  4.                                    from " . TABLE_PRODUCTS_OPTIONS_VALUES . "
  5.                                    where products_options_values_id = '" . (int)$values_id . "'
  6.                                    and language_id = '" . (int)$_SESSION['languages_id'] . "'");
  7.     return $values_values->fields['products_options_values_name'];
  8.   }
 

欢迎来到zen-cart论坛,这里将是你迈进zen-cart世界的起点
有问题到求助版块提问。
快速回复
限80 字节
批量上传需要先选择文件,再选择上传(---删除纯表情和无意义内容,扣1分---)
 
上一个 下一个