专注ECSHOP第九年
始自2007,服务二千多商户,不断为您增光溢彩

ecshop 后台商品属性选择使用多选框[转]

很方便实用的修改,ecshop 商品属性选择使用多选框的形式
修改方法如下:
 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'].”&nbsp;&nbsp;&nbsp;&nbsp;”;
          $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;
  }

 

赞(0) 打赏
未经允许不得转载:阿牛ECSHOP » ecshop 后台商品属性选择使用多选框[转]
分享到: 更多 (0)
1

评论 5

  1. #-49

    这个代码复制进去会出错 好像有些是全角的字符

    imnpc9年前 (2015-07-16)回复
  2. #-48

    不错 学习了!

    最励志官网9年前 (2015-09-06)回复
  3. #-47

    路过,留个脚印,网站很棒!

    歪妖内涵网9年前 (2015-09-07)回复
  4. #-46

    很不错的网站,交换友情链接不,爱奇趣网:http://www.iqiqu.net/?

    爱奇趣分享网9年前 (2015-09-08)回复
  5. #-45

    秒赞不是偶然,是一种态度!

    内涵社9年前 (2015-10-02)回复

阿牛ECSHOP 更专业 更方便

关于我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏