ecshop 颜色属性添加图片 用图片替换颜色

效果

 

下面来修改

总共改三个文件 admin/goods.php ,admin/inculdes/lib_goods.php, 模板目录下的 goods.dwt

1.打开 admin/goods.php 找到 $attr_price = $_POST['attr_price_list'][$key]; 在下行添加

//随心网络科技 s
$attr_images = array('name' => $_FILES['attr_images_list']['name'][$key] , 'type' => $_FILES['attr_images_list']['type'][$key] , 'tmp_name' => $_FILES['attr_images_list']['tmp_name'][$key] , 'error' => $_FILES['attr_images_list']['error'][$key], 'size' => $_FILES['attr_images_list']['size'][$key] );
//随心网络科技 e

2.找到 $goods_attr_list[$attr_id][$attr_value]['attr_price'] = $attr_price; 有两处 分别另起一行添加

//随心网络科技 s
$goods_attr_list[$attr_id][$attr_value]['attr_images'] = $attr_images;
//随心网络科技 e

3. 找到 $sql = "DELETE FROM " .$ecs->table('goods_attr'). " WHERE goods_attr_id = '$info[goods_attr_id]' LIMIT 1";  在下面   $db->query($sql);

下添加 

//随心工作室 s
$goods_attr_id = $info['sign'] == 'insert' ? $db->insert_id() : $info['goods_attr_id'];
if( $info['sign'] == 'insert' || $info['sign'] == 'update' )
{
if( $info['attr_images']['tmp_name'] != '' )
{
$attr_images_dir = 'color/'.$goods_id;
$attr_images_scoure_name = "0-0-$goods_attr_id.jpg";
$color_scoure_images = $image->upload_image($info['attr_images'] , $attr_images_dir , $attr_images_scoure_name ); // 原始图片
}
}
else
{
$attr_color_images_dir = ROOT_PATH.DATA_DIR.'/color/'.$goods_id."/0-0-".$info[goods_attr_id].".jpg";
file_exists($attr_color_images_dir) && unlink( $attr_color_images_dir );
}

//随心工作室 e

 

这个文件里面修改完了。接下来修改  admin/inculdes/lib_goods.php

1.找到 get_attr_list 方法 在SQL里 添加  v.goods_attr_id 

2.找到 <input type="hidden" name="attr_price_list[]" value="0" />  在下面添加

//随心网络科技 strat

$attr_color_images_html = '';
if( $val['goods_attr_id'] && $val['goods_attr_id'] != 0 && $val['goods_attr_id'] != '' )
{
$attr_color_images_dir = "../".DATA_DIR.'/color/'.$goods_id."/0-0-".$val['goods_attr_id'].".jpg";
file_exists($attr_color_images_dir) && $attr_color_images_html = '<span style="border:1px solid #FF6600;"><img src="'.$attr_color_images_dir.'" width="15" height="15" align="absmiddle"></span>';
}
$html .= $val['attr_name'] == '颜色' ? ' 属性图片:<input type="file" name="attr_images_list[]" style=" width:70px;" />'.$attr_color_images_html : '<span style="display:none;"><input type="file" name="attr_images_list[]" value="" /></span>';
//随心网络科技 strat

 

3.在goods.dwt 的属性地方添加 <img src="../data/color/{$goods_id}/0-0-{$value.id}.jpg" style="width:40px; height:40px;" /> 

 

完成

随心网络科技  联系QQ:1595192997

 

 

 

posted @ 2013-08-08 02:49  随心^_^  阅读(3077)  评论(0编辑  收藏  举报