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

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/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 );
}


后台效果图:
未命名11111.jpg

前台效果图:
未命名2222.jpg

前台显示:

方法一:

1. 模板的includes\lib_goods.php文件中:

查找:'id'           => $row['goods_attr_id']);

修改成:'id'           => $row['goods_attr_id'],
                                                        'attr'         => "../".DATA_DIR.'/color/'.get_attachment_by_id($goods_id)."/0-0-".$row['goods_attr_id'].".jpg");

2.在good.dwt中调用

<img src="{$value.attr}" alt="{$value.label}"/>


方法二:

1.在goods.php中找到: 198行左右

$smarty->assign('categories',         get_categories_tree($goods['cat_id']));  // 分类

在后面添加:

$smarty->assign('attr_url',           get_attachment_by_id($goods_id));  // 自定义属性图片

2. 在goods.dwt中调用
<img src="../data/color/{$attr_url}/0-0-{$value.id}.jpg" />


这个 功能我觉得官方应该开发,在 商品页非常直观,用文字说明颜色,说不清楚,最好是关联一下 相册。把颜色图片的 地址写入 ecs_goods_attr 表。
前台效果,我现在还没有做。根据函数get_attachment_by_id ,已经商品id和goods_attr_id 就能取出相对应的颜色图片.
前台完善,我在发效果图..

效果无法关联相册。这是一遗憾。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值