您现在的位置是:首页 > 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';
}

本文标签:

很赞哦! ()

相关源码

  • 帝国cms7.5文库范文/付费下载/复制付费/带支付源码免费下载本模板为文库、文档分享、知识付费类平台设计,提供完整的内容变现解决方案。系统支持多种内容展示与付费模式,满足不同场景下的内容价值转化需求,帮助平台实现内容资源的有效管理和商业化运营。查看源码
  • (自适应)简繁双语响应式服装服饰西装工装校服定制pbootcms模板本模板基于PbootCMS内核开发,为服装服饰行业量身打造,尤其适合西装定制、工装生产、校服订制等服装类企业使用。模板采用响应式布局设计,确保在手机、平板、电脑查看源码
  • (PC+WAP)企业管理工程造价资产评估财务审计带留言网站模板本模板基于PbootCMS内核开发,为工程造价咨询、财务审计类企业量身打造,同时支持多行业快速适配。采用PC+WAP双端同步设计,数据实时互通,助您高效展示企业形象与服务能力。查看源码
  • (自适应)工业机械设备产品介绍免费pbootcms源码下载本网站模板基于PbootCMS内核精心开发,为机械设备与工业产品制造企业量身打造。设计充分考量行业特性,突出产品展示与技术实力呈现查看源码
  • 自适应电子科技类产品公司pbootcms网站模板基于PbootCMS内核开发,为电子科技类企业设计,适用于电子产品展示、企业官网等场景。该模板采用‌开源架构‌,用户可自由访问和修改源码,灵活适配各类行业需求,无需二次开发成本查看源码
  • (响应式H5)帝国cms7.5文章新闻博客模板带会员中心本模板基于帝国CMS内核开发,为新闻资讯、个人博客及作品展示类网站设计。采用响应式布局技术,确保在手机、平板和电脑等不同设备上都能获得良好的浏览体验。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐