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

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

张津广2023-12-11Ecshop商城教程已有人查阅

导读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';
}

本文标签:

很赞哦! ()

相关源码

  • (自适应响应式)环保水净化处理设备阀门等网站源码下载基于PbootCMS内核开发的响应式模板,为水处理设备、空气净化器等环保企业设计,自适应手机端浏览。通过简洁高效的后台管理系统,助力环保科技企业快速建立专业在线展示平台。查看源码
  • (自适应)黑色摄影作品工作室pbootcms模板网站源码下载为风景摄影、个人工作室打造的高端网站模板,基于PbootCMS开源内核开发,采用HTML5自适应架构,PC与移动端实时数据同步,适配各类拍摄作品展示需求。查看源码
  • 宽屏自适应搬家家政快递物流公司网站模板该宽屏大气的响应式网站模板专为搬家公司、家政服务及物流快递企业设计,基于PbootCMS内核开发,通过自适应布局确保手机、PC等多终端体验一致,助力企业高效构建专业在线服务平台。查看源码
  • (PC+WAP)蓝色新能源环保太阳能光伏模板pbootcms下载新能源环保行业网站解决方案为太阳能光伏系统企业打造的专业网站模板,助力新能源企业高效展示产品与服务PbootCMS内核开发,源码开放可修改PC与手机端自适应设计查看源码
  • pbootcms模板(自适应手机版)红色响应式单位机构类网站自适应响应式单位机构网站模板 | PbootCMS内核开发为机构组织设计的响应式网站模板,采用PbootCMS内核开发,支持一键替换行业内容,满足多元化场景需求。查看源码
  • 帝国CMS7.2互联网自媒体门户整站带数据源码免费下载分享一款高仿极客网门户模板,帝国cms7.2版本,非常适合互联网、自媒体、文章门户网站使用。测法发现备份数据恢复报错,找了几个版本的都是一样的,有能力的自行修复查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐