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