现在的位置: 首页 > 综合 > 正文

ecshop添加重量单位

2017年11月26日 ⁄ 综合 ⁄ 共 1326字 ⁄ 字号 评论关闭

1、修改数据表字段长度ecs_goods表goods_weight字段,长度改为15,小数位长度改为6

2、在/languages/zh_cn/admin/goods.php添加单位$_LANG['unit_ml'] = 'ML';

3、在/admin/goods.php文件里写换算公式

if($is_add or $goods['goods_weight'] >= 1){
  $weight_unit='1';
 }else if($goods['goods_weight']/0.01>=1){
  $weight_unit='0.01';
 }else{
  $weight_unit='0.001';
 }

    //$smarty->assign('weight_unit', $is_add ? '1' : ($goods['goods_weight'] >= 1 ? '1' : '0.001'));

$smarty->assign('weight_unit', $weight_unit);

4、还原数据

if($goods['goods_weight'] >= 1){
    $goods_weight_by_unit=$goods['goods_weight'];
   }else if($goods['goods_weight']/0.01>=1){
    $goods_weight_by_unit=$goods['goods_weight'] / 0.01;
   }else{
    $goods_weight_by_unit=$goods['goods_weight'] / 0.001;
   }
            //$goods['goods_weight_by_unit'] = ($goods['goods_weight'] >= 1) ? $goods['goods_weight'] : ($goods['goods_weight'] / 0.001);
   $goods['goods_weight_by_unit'] = $goods_weight_by_unit;

5、添加单位名称。在/languages/zh_cn/common.php

$_LANG['unit_ml'] = 'ML';

6、还原前台数据位录入数据

/includes/lib_goods.php里面有个函数get_goods_info

 

/* 修正重量显示 */
  if(intval($row['goods_weight']) > 0){
   $row['goods_weight']=$row['goods_weight'] . $GLOBALS['_LANG']['kilogram'];
  }else if($row['goods_weight']/0.01>=1){
   $row['goods_weight']=($row['goods_weight'] * 100) . $GLOBALS['_LANG']['unit_ml'];
  }else{
   $row['goods_weight']=($row['goods_weight'] * 1000) . $GLOBALS['_LANG']['gram'];
  }

 

经过以上几步修改即可添加一个重量单位。

 

抱歉!评论已关闭.