# 获取商品类型下的商品信息页面布局的选项值

**URL:** <https://www.isharkfly.com/t/topic/5578>\
**Category:** PHP\
**Created:** [August 10, 2012, 3:36am UTC](https://www.isharkfly.com/t/topic/5578 "2012-08-10T03:36:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [August 10, 2012, 3:36am UTC](https://www.isharkfly.com/t/topic/5578/1 "2012-08-10T03:36:31Z")

</div>

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;
    }
  }
}`
