百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>Ecshop教程> ecshop商品属性选择使用多选框的形式
分享文章到:

ecshop商品属性选择使用多选框的形式

发布时间:12/03 来源: 浏览: 关键词:
  =========== 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;
  }
打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

相关文章

共有18人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板