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

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

当前位置: 主页>网站教程>Ecshop教程> 仿淘宝运费 ecshop提取到商品详细页面
分享文章到:

仿淘宝运费 ecshop提取到商品详细页面

发布时间:12/03 来源: 浏览: 关键词:
 方法:此方法没有调用数据库里那个,而是用JS实现的。

步骤:

1.goods.php(红色为增加的代码)
大概33行:
$goods_id = isset($_REQUEST['id'])  ? intval($_REQUEST['id']) : 0;
$smarty->assign('tc_goods_weight',get_goods_weight($goods_id));//tc:取得商品重量
$smarty->assign('regionname',get_region_name()); //tc:取得全国一级省市

然后在代码尾部加上两个函数:
//tc:取得全国一级城市信息
function get_region_name(){
$sql="SELECT * FROM ecs_region WHERE parent_id ='1';";
return $GLOBALS['db']->getAll($sql);
}
function get_goods_weight($goods_id){
$sql="select goods_weight from ecs_goods where goods_id = '$goods_id';";
$rs = $GLOBALS['db']->getAll($sql);
return $rs[0]['goods_weight'];
}

找到:
<!-- {if $goods.goods_brand neq "" and $cfg.show_brand} 显示商品品牌-->
{$lang.goods_brand}<a href="{$goods.goods_brand_url}" >{$goods.goods_brand}</a><br />    
<!--{/if}-->
至 <label id="flowcity">北京</label><img src="images/selectcity.jpg" /> : 快递 <label id="tc_flowprice"></label>元 <br />
    <div id="showList" style="position:absolute;border:2px solid #ccc; display:none;font-size:12px; padding:5px; background:#fff; width:260px; z-index:99999";>
    <div id="hiddenprice" style="display:none;">{$tc_goods_weight.goods_weight}</div>
    <!--{foreach from=$regionname item=region_names}-->
     <a href="javascript:">{$region_names.region_name}</a>
    <!--{/foreach}-->

最后就是JS:
<!-- {literal} -->
onload = function(){
  changePrice();
  fixpng();
  initprice(); //tc:初始化运费信息
  try { onload_leftTime(); }
  catch (e) {}
}
function initprice(){
var tc_goodsweight = Math.ceil($("hiddenprice").innerText);
tc_goodsweight == 0 ? 1 : tc_goodsweight;
if(tc_goodsweight <=5)
  $("tc_flowprice").innerText = '5';
if(tc_goodsweight >=5 && tc_goodsweight<=10)
  $("tc_flowprice").innerText = '10';
if(tc_goodsweight >=10 && tc_goodsweight<=15)
  $("tc_flowprice").innerText = '15';
if(tc_goodsweight >=15 && tc_goodsweight<=20)
  $("tc_flowprice").innerText = '20';
}

在head的JS里加上函数

/* tc 运费JS */
function createCityList(elem){
var xx = event.clientX;
var yy = event.clientY;
$("showList").style.display='block';
$("showList").style.left=xx+'px';
$("showList").style.top=yy+'px'; 
}
function changeCity(cityname,regid){
var tc_goodsweight = Math.ceil($("hiddenprice").innerText); //取得商品重量
$("flowcity").innerText=cityname;
if(tc_goodsweight== 0)
  tc_goodsweight=1;
else
  tc_goodsweight=tc_goodsweight;
//北京
if(regid==2){
  initprice();
}
//河北 天津
else if(regid==27 || regid==10){  
  if(tc_goodsweight==1){
   $("tc_flowprice").innerText= "8"; //首重
  }else{
   $("tc_flowprice").innerText= ((tc_goodsweight - 1)*3 + 8 ); //续3
  } 
}
//新疆 **
else if(regid==28 || regid==29){
  if(tc_goodsweight==1){
   $("tc_flowprice").innerText= "20"; //首重
  }else{
   $("tc_flowprice").innerText= ((tc_goodsweight - 1)*10 + 20 );//续10
  }
}
//香港
else if(regid==33){
  if(tc_goodsweight==1){
   $("tc_flowprice").innerText= "25"; //首重
  }else{
   $("tc_flowprice").innerText= ((tc_goodsweight - 1)*10 + 25 );//续10
  }
}
//澳门
else if(regid==34){
  if(tc_goodsweight==1){
   $("tc_flowprice").innerText= "35"; //首重
  }else{
   $("tc_flowprice").innerText= ((tc_goodsweight - 1)*20 + 35 );//续10
  }
}
//台湾
else if(regid==35){
  if(tc_goodsweight==1){
   $("tc_flowprice").innerText= "30"; //首重
  }else{
   $("tc_flowprice").innerText= ((tc_goodsweight - 1)*28 + 30 );//续10
  }
}
//其他
else{
  if(tc_goodsweight==1){
   $("tc_flowprice").innerText= "10"; //首重
  }else{
   $("tc_flowprice").innerText= ((tc_goodsweight - 1)*5 + 10 );//续10
  }
}

$("showList").style.display='none';
}
function hideCityList(){
$("showList").style.display='none';
}
打赏

打赏

取消

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

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

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

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

相关文章

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

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板