Ecshop 商品页配送方式添加 实现仿淘宝按地区显示运费

Ecshop实现仿淘宝按地区显示运费

淘宝网(Taobao)购物的宝贝详情页面,可以针对不同地区显示不同运费,运费由后台设定;结算时间,按重量、件数计算运费。Ecshop本身有配送方式插件,已有多家物流公司插件,例如:顺丰快递、申通快递、圆通快递等。本文介绍如何实现按地区显示运费,并且让每个商品绑定运费模板。

1、Ecshop后台配送方式创建

进入Ecshop后台"系统设置-->配送方式",将“顺丰快递”改名称为“粮食快递”,配送ID号为6。

2、商品绑定配送方式的运费模板

2.1 数据表“ecs_goods”增加一个字段,执行下面SQL语句:

1

ALTER TABLE  `ecs_goods` ADD `shipping_id` MEDIUMINT(9) NOT NULL DEFAULT ‘6‘;

2.2 后台添加/编辑 商品 调出已经安装配送方式 "admin/ goods.php ",将此shipping_list函数添加到goods.php最末处。

1

2

3

4

5

6

7

8

9

10

11

12

/**

* 取得已安装的配送方式

* @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());”增加调用代码

1

2

3

4

// LONGHTML 增加运费模板

$smarty->assign(‘shipping_list‘, shipping_list());

// END

$smarty->assign(‘unit_list‘, get_unit_list());

在“/* 处理商品数据 */”后面,增加POST过来的“shipping_id ”表单值进行赋值

1

2

3

4

5

/* 处理商品数据 */

// LONGHTML 运费模板(新增,更新)

$shipping_id = empty($_POST[‘shipping_id‘]) ? ‘0‘ : intval($_POST[‘shipping_id‘]);

// END

最后一步是“插入/更新”商品时,对“shipping_id”字段实现处理。直接替换掉下面代码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

/* 入库 */

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"

1

2

3

4

5

6

7

8

<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页面商品显示部分加入调用代码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

/***** 商品页按地区显示运费 ***********************************************************************/

$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  加在需要显示运费的地方,根据自己需要调整。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

<!--{if $regions}-->

<script src="themes/default/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="images/icon_2.jpg" align="absmiddle" /></a>:<b id="s_a_price">

{foreach from=$value.shippings item=shipping}

{$shipping.shipping_name}{$current_price}元 &nbsp;

{/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}元 &nbsp;{/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,以最贵配送方式计算。买家可以找客服进行,运费改价。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

/**

* 获得上一次用户采用的支付和配送方式

*

* @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步骤,调用商品绑定的配送方式

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

/* 对是否允许修改购物车赋值 */

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

将themes/default/flow.dwt配送方式隐藏掉

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

<!--{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%">&nbsp;</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://blog.uuecs.com/archives/ecshop-achieve-imitation-taobao-freight-by-region.html

时间: 2024-10-07 18:37:01

Ecshop 商品页配送方式添加 实现仿淘宝按地区显示运费的相关文章

自定义View之仿淘宝详情页

自定义View之仿淘宝详情页 转载请标明出处: http://blog.csdn.net/lisdye2/article/details/52353071 本文出自:[Alex_MaHao的博客] 项目中的源码已经共享到github,有需要者请移步[Alex_MaHao的github] 基本介绍 现在的一些购物类App例如淘宝,京东等,在物品详情页,都采用了类似分层的模式,即上拉加载详情的方式,节省了空间,使用户的体验更加的舒适.只要对于某个东西的介绍很多时,都可以采取这样的方式,第一个页面显示

高仿淘宝和聚美优品商城详情页实现《IT蓝豹》

android-vertical-slide-view高仿淘宝和聚美优品商城详情页实现,在商品详情页,向上拖动时,可以加载下一页.使用ViewDragHelper,滑动比较流畅. scrollView滑动到底部的时候,再行向上拖动时,添加了一些阻力.本项目来源:https://github.com/xmuSistone/android-vertical-slide-view主要代码如下:首先先看一下布局:  <com.stone.verticalslide.DragLayout        a

一款仿淘宝购物的商品列表页面多条件查询(含有单选和全部)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Typ

JS仿淘宝详情页菜单条智能定位效果

类似于淘宝详情页菜单条智能定位 对于每个人来说并不陌生!如下截图所示:红色框的那部分! 基本原理: 是用JS侦听滚动事件,当页面的滚动距离(页面滚动的高度)大于或者等于 "对象"(要滚动的对象)距离页面顶部的高度,也就是说滚动的对象与窗口的上边缘接触时,立即将对象定位属性position值改成fixed(固定) (除IE6以外,因为IE6不支持fixed).对于IE6用绝对定位position:absolute,top:就是"游览器滚动的top".在 IE6下浏览看

Vue实现仿淘宝商品详情属性选择的功能

Vue实现仿淘宝商品详情属性选择的功能 2018年09月07日 17:13:35 yx_cos 阅读数:278 先看下效果图:(同个属性内部单选,属性与属性之间可以多选) 主要实现过程: 所使用到的数据类型是(一个大数组里面嵌套了另一个数组)具体格式如下: attrAndValuees: [   {   'attrId': 1,   'attrName': '味道',   'valuees': [   {   'attrId': 1,   'value': '橘子味'   },   {   'a

Android中仿淘宝首页顶部滚动自定义HorizontalScrollView定时水平自动切换图片

Android中仿淘宝首页顶部滚动自定义HorizontalScrollView定时水平自动切换图片 自定义ADPager 自定义水平滚动的ScrollView效仿ViewPager 当遇到要在ViewPager中添加多张网络请求图片的情况下,不能进行复用,导致每次都要重新去求情已经请求过的数据致使流量数据过大 自定义的数据结构解决了这个问题,固定传递的图片数据之后进行统一请求,完成后进行页面切换数据复用 代码中涉及网络请求是用的Volley网络请求框架 PicCarousel是网络数据请求的U

转::iOS 仿淘宝,上拉进入详情页面

今天做的主要是一个模仿淘宝,上拉进入商品详情的功能,主要是通过 tableView 与 webView 一起来实现的,当然也可根据自己的需要把 webView 替换成你想要的 1 // 2 // ViewController.m 3 // 仿淘宝,上拉进入详情 4 // 5 // Created by Amydom on 16/11/22. 6 // Copyright ? 2016年 Amydom. All rights reserved. 7 // 8 9 #import "ViewCont

高仿淘宝客户端

高仿淘宝客户端 仿淘宝安卓客户端的demo源码,主要实现了:商品的基本展示.宝贝详情,图片展示的放大缩小功能.界面之间切换的动画.购物车多项删除.弹窗的动画效果.首页广告的轮播效果.获得本机具有传感器的列表.listView的上拉刷新,下拉加载功能.二维码扫描.刮刮乐等功能和效果. 下载地址:http://www.devstore.cn/code/info/925.html 运行截图:    

基于Bootstrap仿淘宝分页控件实现

.header { cursor: pointer } p { margin: 3px 6px } th { background: lightblue; width: 20% } table { text-align: center; margin-top: 20px; margin-left: 10px; margin-bottom: 20px } a { cursor: pointer; text-decoration: none; color: gray } a:hover { text