=========== 1,修改 admin/includes/lib_goods.php =========
中的function build_attr_html($cat_id, $goods_id = 0){}函数 改为如下
/**
* 根据属性数组创建属性的表单
*
* @access public
* @param int $cat_id 分类编号
* @param int $goods_id 商品编号
* @return string
*/
function build_attr_html($cat_id, $goods_id = 0)
{
$attr = get_attr_list($cat_id, $goods_id);
$tmpAttr = array();
$tmpindex = array();
foreach ($attr AS $tmpk => $tmpv){
if ($tmpv['attr_type'] == 1 || $tmpv['attr_type'] == 2){
if( !in_array(‘a’.$tmpv['attr_id'], $tmpindex) ){
$tmpindex[] = ‘a’.$tmpv['attr_id'];
$attr_values = explode(“\n”, $tmpv['attr_values']);
$tmpAttr['a'.$tmpv['attr_id']]['attr_type'] = $tmpv['attr_type'] ;
$tmpAttr['a'.$tmpv['attr_id']]['attr_name'] = $tmpv['attr_name'] ;
$tmpAttr['a'.$tmpv['attr_id']]['attr_input_type'] = $tmpv['attr_input_type'] ;
$tmpAttr['a'.$tmpv['attr_id']]['attr_id'] = $tmpv['attr_id'] ;
foreach ($attr_values AS $lk)
{
$lk = trim(htmlspecialchars($lk));
$tmpAttr['a'.$tmpv['attr_id']]['selectlist'][$lk]=array(‘select_name’=>$lk,’is_checked’=>0);
}
}
$vk = trim(htmlspecialchars($tmpv['attr_value']));
$tmpAttr['a'.$tmpv['attr_id']]['selectlist'][$vk]['attr_id']=$tmpv['attr_id'];
$tmpAttr['a'.$tmpv['attr_id']]['selectlist'][$vk]['attr_name']=$tmpv['attr_name'];
$tmpAttr['a'.$tmpv['attr_id']]['selectlist'][$vk]['attr_input_type']=$tmpv['attr_input_type'];
$tmpAttr['a'.$tmpv['attr_id']]['selectlist'][$vk]['attr_values']=$tmpv['attr_values'];
$tmpAttr['a'.$tmpv['attr_id']]['selectlist'][$vk]['attr_value']=$tmpv['attr_value'];
$tmpAttr['a'.$tmpv['attr_id']]['selectlist'][$vk]['attr_price']=$tmpv['attr_price'];
$tmpAttr['a'.$tmpv['attr_id']]['selectlist'][$vk]['is_checked']=1;
}else{
$tmpAttr[] = $tmpv;
}
}
$html = ‘<table width=”100%” id=”attrTable”>’;
$spec = 0;
$tix = 0;
foreach ($tmpAttr AS $key => $val)
{
$html .= “<tr><td class=’label’>”;
if ($val['attr_type'] == 1 || $val['attr_type'] == 2)
{
$html .=”$val[attr_name]</td><td style=\”border:1px solid #cdcdcd;\”>”;
}else{
$html .= “$val[attr_name]</td><td><input type=’hidden’ name=’attr_id_list[]‘ value=’$val[attr_id]‘ />”;
}
if ($val['attr_input_type'] == 0)
{
$html .= ‘<input name=”attr_value_list[]” type=”text” value=”‘ .htmlspecialchars($val['attr_value']). ‘” size=”40″ /> ‘;
}
elseif ($val['attr_input_type'] == 2)
{
$html .= ‘<textarea name=”attr_value_list[]” rows=”3″ cols=”40″>’ .htmlspecialchars($val['attr_value']). ‘</textarea>’;
}
elseif( $val['attr_type'] != 1 && $val['attr_type'] != 2 )
{
$html .= ‘<select name=”attr_value_list[]“>’;
$html .= ‘<option value=”">’ .$GLOBALS['_LANG']['select_please']. ‘</option>’;
$attr_values = explode(“\n”, $val['attr_values']);
foreach ($attr_values AS $opt)
{
$opt = trim(htmlspecialchars($opt));
$html .= ($val['attr_value'] != $opt) ?
‘<option value=”‘ . $opt . ‘”>’ . $opt . ‘</option>’ :
‘<option value=”‘ . $opt . ‘” selected=”selected”>’ . $opt . ‘</option>’;
}
$html .= ‘</select> ‘;
}else{
$html .= ‘<div>’;
foreach ($val['selectlist'] AS $selkey => $selvalue){
$tix++;
$html .=”<div style=\”float:left; width:190px;\”><table><tr><td><input type=’checkbox’ id=’checkset_$tix’”. ($selvalue['is_checked'] ? “checked” : “” ) .” onclick=\”setattrdisable(this,’$tix’,'selectvalue_’,'selectprice_’,'selectattr_’)\”>”.$selvalue['select_name'].” ”;
$html .=”<input id=’selectvalue_”.$tix.”‘ type=’hidden’ name=’attr_value_list[]‘ value=\”".$selvalue['select_name'].”\” “. ($selvalue['is_checked'] ? “” : ‘disabled’ ) .” > </td>”;
$html .=”<td>”.$GLOBALS['_LANG']['spec_price'].’ <input type=”text” name=”attr_price_list[]” value=”‘ . $selvalue['attr_price'] . ‘” size=”5″ maxlength=”10″ ‘. ($selvalue['is_checked'] ? “” : ‘disabled’ ) .’ id=”selectprice_’.$tix.’” />’.
“<input type=’hidden’ id=’selectattr_”.$tix.”‘ name=’attr_id_list[]‘ value=’$val[attr_id]‘ “. ($selvalue['is_checked'] ? “” : ‘disabled’ ) .” /> </td></tr></table></div>”;
}
$html .= ‘</div>’;
}
$html .= ($val['attr_type'] == 1 || $val['attr_type'] == 2) ? ” “:
‘ <input type=”hidden” name=”attr_price_list[]” value=”0″ />’;
$html .= ‘</td></tr>’;
}
$html .= ‘</table>’;
return $html;
}
======== 2,修改 admin/templates/goods_info.htm 加一个js函数上去============
function setattrdisable(obj,ix,sv,sp,sa){
document.getElementById(sv+ix).disabled = obj.checked ? false : true;
document.getElementById(sp+ix).disabled = obj.checked ? false : true;
document.getElementById(sa+ix).disabled = obj.checked ? false : true;
} (责任编辑:最模板) |