您现在的位置是:首页 > 教程 > ecshop商城教程ecshop商城教程

ecshop商品页仿淘宝运费查询功能的实现方法

张津广2023-12-11 17:14:25ecshop商城教程已有人查阅

导读ecshop 仿淘宝运费方法:此方法没有调用数据库里那个,而是用JS实现的。1.goods.php(红 为增加的代码)

ecshop 仿淘宝运费方法:此方法没有调用数据库里那个,而是用JS实现的。
ecshop 仿淘宝运费步骤:
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';
}

本文标签:

很赞哦! ()

留言与评论 (共有 条评论)
验证码:

本栏推荐

相关标签