Ecshop实现仿Taobao地区运费模板
目录:
1、Ecshop后台配送方式创建
2、商品绑定配送方式的运费模板
2.1 数据表“ecs_goods”增加一个字段,执行下面SQL语句:
2.2 后台添加/编辑 商品 调出已经安装配送方式 "admin/ goods.php ",将此shipping_list函数添加到goods.php最末处。
2.3 后台添加/编辑商品 实现绑定配送方式"admin/goods_info.htm"
3、前台商品详情调用设置好的配送方式
4、结算流程中,根据配送地址计算运费
4.1 重写“include/lib_order.php”中last_shipping_and_payment函数。多个商品,不同配送方式,调用配送方式ID,以最贵配送方式计算。买家可以找客服进行,运费改价。
5、经过上面多处增加/修改,测试一下运行效果。
淘宝网(Taobao)购物的宝贝详情页面,可以针对不同地区显示不同运费,运费由后台设定;结算时间,按重量、件数计算运费。Ecshop本身有
配送方式插件,已有多家物流公司插件,例如:顺丰快递、申通快递、圆通快递等。本文介绍如何实现按地区显示运费,并且让每个商品绑定运费模板。
1、Ecshop后台配送方式创建
进入Ecshop后台"系统设置-->配送方式",将“顺丰快递”改名称为“粮食快递”,配送ID号为6。
2、商品绑定配送方式的运费模板
2.1 数据表“ecs_goods”增加一个字段,执行下面SQL语句:
ALTER TABLE `ecs_goods` ADD `shipping_id` MEDIUMINT(9) NOT NULL DEFAULT '6';
2.2 后台添加/编辑 商品 调出已经安装配送方式 "admin/ goods.php ",将此shipping_list函数添加到goods.php最末处。
/**
* 取得已安装的配送方式
* @return array 已安装的配送方式
*/
function shipping_list()
{
$sql = 'SELECT shipping_id, shipping_name ' .
'FROM ' . $GLOBALS['ecs']->table('shipping') .
' WHERE enabled = 1'; return $GLOBALS['db']->getAll($sql);
}
在代码前“$smarty->assign('unit_list', get_unit_list());”增加调用代码
// LONGHTML 增加运费模板
$smarty->assign('shipping_list', shipping_list());
// END
$smarty->assign('unit_list', get_unit_list());
在“/* 处理商品数据 */”后面,增加POST过来的“shipping_id ”表单值进行赋值
/* 处理商品数据 */ // LONGHTML 运费模板(新增,更新)
$shipping_id = empty($_POST['shipping_id']) ? '0' : intval($_POST['shipping_id']);
// END
最后一步是“插入/更新”商品时,对“shipping_id”字段实现处理。直接替换掉下面代码
/* 入库 */
if ($is_insert)
{
if ($code == '')
{
$sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .
"cat_id, brand_id, shop_price, logi_cost, market_price, is_promote, promote_price, " .
"promote_start_date, promote_end_date, goods_img, index_img, goods_thumb, original_img, keywords, goods_brief, " .
"seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, " .
"is_on_sale, is_alone_sale, is_shipping, goods_desc, add_time, last_update, goods_type, rank_integral, suppliers_id, province, city, virtual_buy,shipping_id)" .
"VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .
"'$brand_id', '$shop_price', '$logi_cost', '$market_price', '$is_promote','$promote_price', ".
"'$promote_start_date', '$promote_end_date', '$goods_img', '$index_img', '$goods_thumb', '$original_img', ".
"'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".
" '$warn_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', '$is_on_sale', '$is_alone_sale', $is_shipping, ".
" '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$rank_integral', '$suppliers_id', '$goods_provincestr', '$goods_citystr', '$virtual_buy', '$shipping_id' )";
}
else
{
$sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .
"cat_id, brand_id, shop_price, logi_cost, market_price, is_promote, promote_price, " .
"promote_start_date, promote_end_date, goods_img, index_img, goods_thumb, original_img, keywords, goods_brief, " .
"seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, is_real, " .
"is_on_sale, is_alone_sale, is_shipping, goods_desc, add_time, last_update, goods_type, extension_code, rank_integral, province, city, virtual_buy,shipping_id)" .
"VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .
"'$brand_id', '$shop_price', '$logi_cost', '$market_price', '$is_promote','$promote_price', ".
"'$promote_start_date', '$promote_end_date', '$goods_img', '$index_img', '$goods_thumb', '$original_img', ".
"'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".
" '$warn_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', 0, '$is_on_sale', '$is_alone_sale', $is_shipping, ".
" '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$code', '$rank_integral', '$goods_provincestr', '$goods_citystr', '$virtual_buy', '$shipping_id')";
}
}
else
{
/* 如果有上传图片,删除原来的商品图 */
$sql = "SELECT goods_thumb, goods_img, index_img, original_img " .
" FROM " . $ecs->table('goods') .
" WHERE goods_id = '$_REQUEST[goods_id]'";
$row = $db->getRow($sql);
if ($proc_thumb && $goods_img && $row['goods_img'] && !goods_parse_url($row['goods_img']))
{
@unlink(ROOT_PATH . $row['goods_img']);
@unlink(ROOT_PATH . $row['original_img']);
} if ($proc_thumb && $goods_thumb && $row['goods_thumb'] && !goods_parse_url($row['goods_thumb']))
{
@unlink(ROOT_PATH . $row['goods_thumb']);
} if ($index_img && $row['index_img'] && !goods_parse_url($row['index_img']))
{
@unlink(ROOT_PATH . $row['index_img']);
} $sql = "UPDATE " . $ecs->table('goods') . " SET " .
"goods_name = '$_POST[goods_name]', " .
"goods_name_style = '$goods_name_style', " .
"goods_sn = '$goods_sn', " .
"cat_id = '$catgory_id', " .
"brand_id = '$brand_id', " .
"shop_price = '$shop_price', " .
"logi_cost = '$logi_cost', " .
"market_price = '$market_price', " .
"is_promote = '$is_promote', " .
"promote_price = '$promote_price', " .
"promote_start_date = '$promote_start_date', " .
"suppliers_id = '$suppliers_id', " .
"province = '$goods_provincestr', " .
"city = '$goods_citystr', " .
"virtual_buy = '$virtual_buy', " .
"shipping_id = '$shipping_id', " .
"promote_end_date = '$promote_end_date', "; /* 如果有上传图片,需要更新数据库 */
2.3 后台添加/编辑商品 实现绑定配送方式"admin/goods_info.htm"
<tr>
<td class="label">运费模板</td>
<td><select name="shipping_id" ><option value="0">{$lang.select_please}
{foreach from=$shipping_list item=shipping}
<option value="{$shipping.shipping_id}" {if $shipping.shipping_id eq $goods.shipping_id}selected{/if}>{$shipping.shipping_name}</option>
{/foreach}
</select>{$lang.require_field}</td>
</tr>
在品牌下面,增加绑定运费模板。效果如下:
3、前台商品详情调用设置好的配送方式
以主题default为例,增加新文件:
1、chrome.js (themes/default/js)
2、icon_2.jpg (themes/default/images)
goods.php页面商品显示部分加入调用代码
/***** 商品页按地区显示运费 ***********************************************************************/
$shippings = array();
$res = $db->GetAll("SELECT shipping_name, shipping_id FROM ecs_shipping WHERE shipping_id=".$goods['shipping_id']);
foreach ($res as $value)
{
$areas = array();
$res1 = $db->GetAll("SELECT * FROM ecs_shipping_area WHERE shipping_id = $value[shipping_id]");
foreach ($res1 as $area)
{
$configure = unserialize($area['configure']);
if (is_array($configure))
{
foreach ($configure as $c)
{
if ($c['name'] == 'base_fee')
{
$price = $c['value'];
}
}
}
$sql = "SELECT a.region_id, r.region_name ".
"FROM ".$ecs->table('area_region')." AS a, ".$ecs->table('region'). " AS r ".
"WHERE r.region_id=a.region_id AND a.shipping_area_id='$area[shipping_area_id]'";
$res2 = $db->query($sql);
while ($arr = $db->fetchRow($res2))
{
$value['areas'][$arr['region_name']] = $price;
}
}
$shippings[] = $value;
}
$res = $db->GetAll("SELECT region_id,region_name FROM ecs_region WHERE parent_id = 1");
if($goods['shipping_id'] == 6)
{
$current_region = '广东'; //默认显示广东省
$smarty->assign('current_region', $current_region);
$smarty->assign('current_price', '7');
} foreach ($res as $value)
{
$row = array();
foreach ($shippings as $a => $shipping)
{
if ($shipping['areas'])
{
foreach ($shipping['areas'] as $key => $price)
{
if ($key == $value['region_name'])
{
$row[$a]['shipping_price'] = $price;
}
}
}
if ($row[$a]['shipping_price'] > 0)
{
$row[$a]['shipping_name'] = $shipping['shipping_name'];
$value['shippings'] = $row;
}
}
if ($value['shippings']) $regions[] = $value;
}
$smarty->assign('regions', $regions);
/****************************************************************************/
goods.dwt 加在需要显示运费的地方
<!--{if $regions}-->
<script src="themes/yihaodian/js/chrome.js" type="text/javascript"></script>
{foreach from=$regions key=key item=value}
{if $key == 0}
<p id="chromemenu">至 <a rel="dropmenu1" href="javascript:;"><b id="s_a_name">{$current_region}</b><img style="margin:0 2px 0 2px;" src="data:images/icon_2.jpg" align="absmiddle" /></a>:<b id="s_a_price">
{foreach from=$value.shippings item=shipping}
{$shipping.shipping_name}{$current_price}元
{/foreach}
</b>
</p>
{/if}
{/foreach}
<div id="dropmenu1" class="dropmenudiv">
{foreach from=$regions item=value}
<a href="javascript:;" onclick="show_shipping('{$value.region_name}','{foreach from=$value.shippings item=shipping}{$shipping.shipping_name}{$shipping.shipping_price}元 {/foreach}')">{$value.region_name}</a>
{/foreach}
</div>
<script>
function show_shipping(name,price)
{
document.getElementById("s_a_name").innerHTML = name;
document.getElementById("s_a_price").innerHTML = price;
}
cssdropdown.startchrome("chromemenu");
</script>
<style>
#chromemenu b { font-weight:normal}
.dropmenudiv {position:absolute;top: 0;z-index:100;width:200px;visibility: hidden; background:#fdffee; padding:8px; border:solid #ffbf69 2px; line-height:25px;}
.dropmenudiv a { margin:0 5px 0 5px;}
</style>
<!--{/if}-->
前台显示最终效果图,默认广东省
4、结算流程中,根据配送地址计算运费
4.1 重写“include/lib_order.php”中last_shipping_and_payment函数。多个商品,不同配送方式,调用配送方式ID,以最贵配送方式计算。买家可以找客服进行,运费改价。
/**
* 获得上一次用户采用的支付和配送方式
*
* @access public
* @return void
*/
function last_shipping_and_payment()
{
$sql = "SELECT shipping_id, pay_id " .
" FROM " . $GLOBALS['ecs']->table('order_info') .
" WHERE user_id = '$_SESSION[user_id]' " .
" ORDER BY order_id DESC LIMIT 1";
$row = $GLOBALS['db']->getRow($sql); /* LONGHTML 获得购物车中商品 运费模板最大值 */
$sql = "SELECT DISTINCT max(g.shipping_id) as shipping_id " .
" FROM " . $GLOBALS['ecs']->table('cart') ." AS c ".
" LEFT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g ON c.goods_id = g.goods_id" .
" WHERE c.`session_id` = '" . SESS_ID . "'".
" AND c.`extension_code` != 'package_buy' ";
$shipping_id = $GLOBALS['db']->getOne($sql);
$row['shipping_id'] = $shipping_id;
// END if (empty($row))
{
/* 如果获得是一个空数组,则返回默认值 */
$row = array('shipping_id' => 0, 'pay_id' => 0);
} return $row;
}
4.2 flow.php购物流程checkout,done步骤,调用商品绑定的配送方式
/* 对是否允许修改购物车赋值 */
if ($flow_type != CART_GENERAL_GOODS || $_CFG['one_step_buy'] == '1')
{
$smarty->assign('allow_edit_cart', 0);
}
else
{
$smarty->assign('allow_edit_cart', 1);
} // LONGHTML 最大值的运费模板
$arr = last_shipping_and_payment();
$_SESSION['flow_order']['shipping_id'] = $arr['shipping_id'];
$smarty->assign('select_shipping_id', $arr['shipping_id']);
// END
/* 检查收货人信息是否完整 */
if (!check_consignee_info($consignee, $flow_type))
{
/* 如果不完整则转向到收货人信息填写界面 */
ecs_header("Location: flow.php?step=consignee\n");
exit;
} $_POST['how_oos'] = isset($_POST['how_oos']) ? intval($_POST['how_oos']) : 0;
$_POST['card_message'] = isset($_POST['card_message']) ? htmlspecialchars($_POST['card_message']) : '';
$_POST['inv_type'] = !empty($_POST['inv_type']) ? htmlspecialchars($_POST['inv_type']) : '';
$_POST['inv_payee'] = isset($_POST['inv_payee']) ? htmlspecialchars($_POST['inv_payee']) : '';
$_POST['inv_content'] = isset($_POST['inv_content']) ? htmlspecialchars($_POST['inv_content']) : '';
$_POST['postscript'] = isset($_POST['postscript']) ? htmlspecialchars($_POST['postscript']) : ''; // LONGHTML 最大值的运费模板
$arr = last_shipping_and_payment();
$_SESSION['flow_order']['shipping_id'] = $arr['shipping_id'];
// END
将themes/default/flow.dwt配送方式隐藏掉
<!--{if $total.real_goods_count neq 0}-->
<div class="" style="display:none;">
<h5><span>{$lang.shipping_method}</span></h5>
<table width="984" align="center" border="0" cellpadding="5" cellspacing="1" bgcolor="#dddddd" id="shippingTable">
<tr align="center">
<th align="center" bgcolor="#ffffff" width="5%"> </th>
<th align="center" bgcolor="#ffffff" width="25%">{$lang.name}</th>
<th align="center" bgcolor="#ffffff">{$lang.describe}</th>
<th align="center" bgcolor="#ffffff" width="15%">{$lang.fee}</th>
<th align="center" bgcolor="#ffffff" width="15%">{$lang.free_money}</th>
<th align="center" bgcolor="#ffffff" width="15%">{$lang.insure_fee}</th>
</tr>
<!-- {foreach from=$shipping_list item=shipping} 循环配送方式 -->
<tr align="center">
<td align="center" bgcolor="#ffffff" valign="top"><input name="shipping" id="shipping_se" type="radio" value="{$shipping.shipping_id}" {if ($order.shipping_id eq $shipping.shipping_id) or true}checked="true"{/if} supportCod="{$shipping.support_cod}" insure="{$shipping.insure}" onclick="selectShipping(this)" />
</td>
<td align="center" bgcolor="#ffffff" valign="top"><strong>{$shipping.shipping_name}</strong></td>
<td align="center" bgcolor="#ffffff" valign="top">{$shipping.shipping_desc}</td>
<td bgcolor="#ffffff" align="center" valign="top">{$shipping.format_shipping_fee}</td>
<td bgcolor="#ffffff" align="center" valign="top">{$shipping.free_money}</td>
<td bgcolor="#ffffff" align="center" valign="top">{if $shipping.insure neq 0}{$shipping.insure_formated}{else}{$lang.not_support_insure}{/if}</td>
</tr>
<!-- {/foreach} 循环配送方式 -->
<!-- LONGHTML --><script>selectShipping02({$select_shipping_id});</script> <!-- END -->
<tr align="center">
<td colspan="6" bgcolor="#ffffff" align="center"><label for="ECS_NEEDINSURE">
<input name="need_insure" id="ECS_NEEDINSURE" type="checkbox" onclick="selectInsure(this.checked)" value="1" {if $order.need_insure}checked="true"{/if} {if $insure_disabled}disabled="true"{/if} />
{$lang.need_insure} </label></td>
</tr>
</table>
</div>
<div class="blank"></div>
<!--{else}-->
<input name = "shipping" type="radio" value = "-1" checked="checked" style="display:none"/>
<!--{/if}-->
5、经过上面多处增加/修改,测试一下运行效果。
广东 首重10KG 7元,续重0.7元/KG
转载:http://www.cnblogs.com/zgzy/p/3822886.html
Ecshop实现仿Taobao地区运费模板的更多相关文章
- ecshop去掉“云服务中心”或者是“模板堂知识库”
ECSHOP开发中心(www.68ecshop.com)教程介绍一下如何去除后台云服务中心菜单: 打开admin/templates/menu.htm,把415行的 document.getEleme ...
- magneto创建运费模板
Magento系统自带了大概7种运费方式:平价.运费表.免运费.ups.usps.fedex.dhl等.不过这些依然无法满足我们的需求,这时候就需要创建一个shipping module 来实现了.创 ...
- PB测款方法 店铺运费模板 设置
https://www.wishhack.com/article/44.html 子账号有权限设置运费
- 仿360影视网站模板html
链接:http://pan.baidu.com/s/1mhIkV4s 密码:9wgq
- ECSHOP模板标签
模板制作修改经常用到ecshop模板标签: 页面关键字 {$keywords }页面标题 {$page_title}产品分类父分类列表 {foreach from=$categories item=c ...
- Ecshop 学习之路一 2016年6月30日
以前下载ecshop 都是在ecshop官网上下载,前后台模板都很难看.功能也不太齐全,这次在模板堂下载了ecshop 模板 仿小米的.做一个简单的电商网站. 页面结构还是挺简单的.功能也齐全.用ec ...
- ecshop 后台批量上传商品 完整上传
ecshop 后台批量上传商品,之所以无法上传,是因为后台上传php文件方法中没有导入商品原图路径 将ecshop根目录中的admin/goods_batch.php文件全部修改为 <?php ...
- ecshop 的一些常用操作
ecshop商品详细页显示已售商品数量和评论数量 ecshop增加已售数量和评论数量很简单,步骤如下,原创文章转载请指明同盟者网络<http://blog.sina.com.cn/tomener ...
- 如何让ECSHOP不同的分类调用不同模板方法
如何给ecshop商品分类,显示不同的模板的话.可以通过不同的分类ID来取得不同模板.我们可以通过分类ID来判断,比如分类为1的,调用cat1.dwt.分类为2的,调用cat2.dwt,我们在cate ...
随机推荐
- cocos2d-x lua 实现单例(管理类)
cocos2d-x lua 实现单例(管理类) version: cocos2d-x 3.6 示例代码 local DogManager = class("DogManager") ...
- MySQL Index Condition Pushdown(ICP) 优化
本文是作者留下的一个坑,他去上茅坑了.茅坑是谁?你猜.
- Objective-C ,ios,iphone开发基础:3分钟教你做一个iphone手机浏览器
第一步:新建一个Single View工程: 第二步:新建好工程,关闭arc. 第三步:拖放一个Text Field 一个UIButton 和一个 UIWebView . Text Field 的ti ...
- 最长非降/下降子序列问题(DP)(待续...)
注意:抽象成以下描述即为最长非降/下降子序列问题(一维状态) 问题描述:在一个无序的序列a1,a2,a3,a4…an里,找到一个最长的序列满足:(不要求连续) ai<=aj<=ak…< ...
- hdu 4582 树状DP
思路:首先声明我是参考:http://blog.csdn.net/frog1902/article/details/9921845这位大牛的博客的. 他说的已经很详尽,但我还是要补充几点. 看完他的解 ...
- Windwos下Apache的缓存设置
1.打开httpd.conf,找到以下几个Module并将其启用(如果没有,可以自行添加) mod_proxy.so(module_proxy) m ...
- asp.net php asp jsp 301重定向的代码
介绍一下针对各类程序系统实施301重定向的代码: 1.Linux主机重定向 Godaddy的Liunx主机,Godaddy本身已经支持Apache,所以直接创建一个.htaccess文件就可以了,一般 ...
- JDBC之初识
JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和接口 ...
- xheditor上传图片的java实现
最近一个项目中因为框架的原因,很多文本编辑器都不兼容,最后找到xheditor,这个富文本编辑器的确不错,功能基本都能满足,只是上传图片的java接口需要自己写,因此,测试了两种方法,最终成功.分享给 ...
- HOWTO: Be more productive
---by Aaron Swartz HOWTO: Be more productive “With all the time you spend watching TV,” he tells m ...