广州传奇网络

地址:广州市天河区东圃大马路富华楼C座

电话:13808825895

邮箱:gz020wbs@163.com

QQ:1564443073

网址:http://www.020wbs.com/

首页 > 二次开发Ecshop二次开发 > 共享在商品详细页,用图片替换颜色

二次开发Ecshop二次开发

二次开发Ecshop二次开发

共享在商品详细页,用图片替换颜色

前几天,碰到了这个问题,开始在整个坛子里找,都没有满意的答案。
所以决定自己制作,出于程序的改动,给后续官方升级带来的不便,没有修改数据库.
1.在 includes/lib_common.php 文件中 增加一个 get_attachment_by_id 函数.
function get_attachment_by_id( $id )
{
if( $id == '' || $id == 0 )
{
exit("Function :get_attachment_by_id parame $id Is Not Legaled");
}
$number = 6;
$size = 2;

$string = sprintf("%06d", $id);
$path = array();

for( $i = 0 ;$i < $number/$size ; $i ++)
{
$path[] = substr($string, $i*$size, $size);
}

return implode('/', $path);
}
2. 修改admin/includes/lib_goods.php .
(1)找到 $html .= ($val['attr_type'] == 1 || $val['attr_type'] == 2) ,修改函数build_attr_html,大约在714行.
在这句后增加下面代码:
$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/'.get_attachment_by_id($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'] == '颜色' ? '<span>   属性图片:<input type="file" name="attr_images_list[]" value="' . $val['attr_images_list'] . '" /></span> '.$attr_color_images_html : '<span style="display:none;"><input type="file" name="attr_images_list[]" value="" /></span>';
(2)修改函数get_attr_list中的$sql变量,增加提取的数据项 v.goods_attr_id

3.修改admin/includes/goods.php,
(1)找到 $attr_price = $_POST['attr_price_list'][$key]; 大约在976行,后面添加:
$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] );
(2)找到$goods_attr_list[$attr_id][$attr_value]['attr_price'] = $attr_price;后两处,大约在983行和989行,后面分别添加:
$goods_attr_list[$attr_id][$attr_value]['attr_images'] = $attr_images;
(3)找到$db->query($sql);大约在1026,这个有多处(请注意行数),在后面增加:
$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/'.get_attachment_by_id($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/'.get_attachment_by_id($goods_id)."/0-0-".$info[goods_attr_id].".jpg";
file_exists($attr_color_images_dir) && unlink( $attr_color_images_dir );
}