# Zen\_has\_product\_attributes 函数解析

**URL:** <https://www.isharkfly.com/t/zen-has-product-attributes/5563>\
**Category:** PHP\
**Created:** [August 9, 2012, 3:13am UTC](https://www.isharkfly.com/t/zen-has-product-attributes/5563 "2012-08-09T03:13:59Z")\
**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 9, 2012, 3:13am UTC](https://www.isharkfly.com/t/zen-has-product-attributes/5563/1 "2012-08-09T03:13:59Z")

</div>

zen\_has\_product\_attributes($products\_id, $not\_readonly = ‘true’)  
该函数主要检查一个指定ID的商品是否有属性。如果商品的属性为只读时，并且PRODUCTS\_OPTIONS\_TYPE\_READONLY\_IGNORED属性设置为显示（1）–该值可在后台管理-配置信息-属性设置-只读选项类型 - 忽略添加到购物车中设置，那么该属性就添加到购物车中,否则就忽略该属性。  
主要查询了 products\_attributes和products\_options 表。在includes/database\_tables.php中定义：  
define(‘TABLE\_PRODUCTS\_ATTRIBUTES’, DB\_PREFIX . ‘products\_attributes’);  
define(‘TABLE\_PRODUCTS\_OPTIONS’, DB\_PREFIX . ‘products\_options’);  
\*/` function zen_has_product_attributes($products_id, $not_readonly = 'true') {
        global $db;
        if (PRODUCTS_OPTIONS_TYPE_READONLY_IGNORED == '1' and $not_readonly == 'true') {
          // don't include READONLY attributes to determin if attributes must be selected to add to cart
          $attributes_query = "select pa.products_attributes_id
                               from " . TABLE_PRODUCTS_ATTRIBUTES . " pa left join " . TABLE_PRODUCTS_OPTIONS . " po on pa.options_id = po.products_options_id
                               where pa.products_id = '" . (int)$products_id . "' and po.products_options_type != '" . PRODUCTS_OPTIONS_TYPE_READONLY . "' limit 1";
        } else {
          // regardless of READONLY attributes no add to cart buttons
          $attributes_query = "select pa.products_attributes_id
                               from " . TABLE_PRODUCTS_ATTRIBUTES . " pa
                               where pa.products_id = '" . (int)$products_id . "' limit 1";
        }
        $attributes = $db->Execute($attributes_query);
        if ($attributes->recordCount() > 0 && $attributes->fields['products_attributes_id'] > 0) {
          return true;
        } else {
          return false;
        }
      }`
