zen_get_show_product_switch_name($lookup, $field, $suffix= ‘SHOW_’, $prefix= ‘INFO’, $field_prefix= '’, $field_suffix=‘’)
该函数主要是通过商品的ID和输入的指定的商品属性返回该属性的设置值。返回的值得就像(SHOW_PRODUCT_INFO_MODEL),
而该函数就是这样返回该值:zen_get_show_product_switch($products_id, ‘model’)。
该函数的工作机制就是通过商品ID获取该商品的商品类型,然后通过商品的类型来获取该类型的商品的处理类型。结合第二个参数,比如:商品型号(model),这样返回的就是SHOW_PRODUCT_INFO_MODEL,SHOW_DOCUMENT_PRODUCT_INFO_MODEL,SHOW_PRODUCT_MUSIC_INFO_MODEL,SHOW_PRODUCT_FREE_SHIPPING_INFO_MODEL。因为商品类型分四种,所以可能返回四种可能,如果该商品是哪一种类型就返回对应的值。该值在页面加载的时候已经从数据库读取出来并被定义成常量,可以直接使用,一般都是做为判断是否显示商品的属性来使用。
主要查询了 products,product_types 表。在includes/database_tables.php中定义:
define(‘TABLE_PRODUCTS’, DB_PREFIX . ‘products’);
define(‘TABLE_PRODUCT_TYPES’, DB_PREFIX . ‘product_types’);
函数源代码:function zen_get_show_product_switch_name($lookup, $field, $suffix= 'SHOW_', $prefix= '_INFO', $field_prefix= '_', $field_suffix='') {
global $db;
$sql = "select products_type from " . TABLE_PRODUCTS . " where products_id='" . (int)$lookup . "'";
$type_lookup = $db->Execute($sql);
$sql = "select type_handler from " . TABLE_PRODUCT_TYPES . " where type_id = '" . (int)$type_lookup->fields['products_type'] . "'";
$show_key = $db->Execute($sql);
$zv_key = strtoupper($suffix . $show_key->fields['type_handler'] . $prefix . $field_prefix . $field . $field_suffix);
return $zv_key;
}zen_get_show_product_switch($lookup, $field, $suffix= ‘SHOW_’, $prefix= ‘INFO’, $field_prefix= '’, $field_suffix=‘’)
该函数跟zen_get_show_product_switch_name的作用差不多一样,前一个函数返回的是属性的名字,而这个函数返回的是属性值。
不一样的是,该函数在商品类型布局表中找不到该值的话,会进入到配置表中查询,如果找不到就返回false。
主要查询了 products,product_types,product_type_layout,configuration 表。在includes/database_tables.php中定义:
define(‘TABLE_PRODUCTS’, DB_PREFIX . ‘products’);
define(‘TABLE_PRODUCT_TYPES’, DB_PREFIX . ‘product_types’);
define(‘TABLE_PRODUCT_TYPE_LAYOUT’, DB_PREFIX . ‘product_type_layout’);
define(‘TABLE_CONFIGURATION’, DB_PREFIX . ‘configuration’);
函数源代码:function zen_get_show_product_switch($lookup, $field, $suffix= 'SHOW_', $prefix= '_INFO', $field_prefix= '_', $field_suffix='') {
global $db;
$sql = "select products_type from " . TABLE_PRODUCTS . " where products_id='" . $lookup . "'";
$type_lookup = $db->Execute($sql);
$sql = "select type_handler from " . TABLE_PRODUCT_TYPES . " where type_id = '" . $type_lookup->fields['products_type'] . "'";
$show_key = $db->Execute($sql);
$zv_key = strtoupper($suffix . $show_key->fields['type_handler'] . $prefix . $field_prefix . $field . $field_suffix);
$sql = "select configuration_key, configuration_value from " . TABLE_PRODUCT_TYPE_LAYOUT . " where configuration_key='" . $zv_key . "'";
$zv_key_value = $db->Execute($sql);
if ($zv_key_value->RecordCount() > 0) {
return $zv_key_value->fields['configuration_value'];
} else {
$sql = "select configuration_key, configuration_value from " . TABLE_CONFIGURATION . " where configuration_key='" . $zv_key . "'";
$zv_key_value = $db->Execute($sql);
if ($zv_key_value->RecordCount() > 0) {
return $zv_key_value->fields['configuration_value'];
} else {
return false;
}
}
}