轻源码

  • QingYuanMa.com
  • 全球最大的互联网技术和资源下载平台
搜索
一起源码网 门户 ECShop网店 查看主题

ECSHOP运费配送方式仿淘宝地区运费模板功能开发

发布者: 觉醒的白河愁 | 发布时间: 2018-7-26 22:09| 查看数: 5018| 评论数: 1|帖子模式

运费配送方式仿淘宝地区运费模板功能开发
目录:
1、后台配送方式创建
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语句:
  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. * @return  array   已安装的配送方式*/function shipping_list()
  4. {    $sql = 'SELECT shipping_id, shipping_name ' .
  5.             'FROM ' . $GLOBALS['ecs']->table('shipping') .
  6.             ' WHERE enabled = 1';    return $GLOBALS['db']->getAll($sql);
  7. }
复制代码

在代码前“$smarty->assign('unit_list', get_unit_list());”增加调用代码
  1. // LONGHTML 增加运费模板$smarty->assign('shipping_list', shipping_list());// END$smarty->assign('unit_list', get_unit_list());
复制代码


在“/* 处理商品数据 */”后面,增加POST过来的“shipping_id ”表单值进行赋值
  1. /* 处理商品数据 */// LONGHTML 运费模板(新增,更新)$shipping_id = empty($_POST['shipping_id']) ? '0' : intval($_POST['shipping_id']);// END
复制代码


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


  1. /* 入库 */
  2.     if ($is_insert)
  3.     {        if ($code == '')
  4.         {            $sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .
  5.                     "cat_id, brand_id, shop_price, logi_cost, market_price, is_promote, promote_price, " .
  6.                     "promote_start_date, promote_end_date, goods_img, index_img, goods_thumb, original_img, keywords, goods_brief, " .
  7.                     "seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, " .
  8.                     "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)" .
  9.                 "VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .
  10.                     "'$brand_id', '$shop_price', '$logi_cost', '$market_price', '$is_promote','$promote_price', ".
  11.                     "'$promote_start_date', '$promote_end_date', '$goods_img', '$index_img', '$goods_thumb', '$original_img', ".
  12.                     "'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".
  13.                     " '$warn_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', '$is_on_sale', '$is_alone_sale', $is_shipping, ".
  14.                     " '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$rank_integral', '$suppliers_id', '$goods_provincestr', '$goods_citystr', '$virtual_buy', '$shipping_id' )";
  15.         }        else
  16.         {            $sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .
  17.                     "cat_id, brand_id, shop_price, logi_cost, market_price, is_promote, promote_price, " .
  18.                     "promote_start_date, promote_end_date, goods_img, index_img, goods_thumb, original_img, keywords, goods_brief, " .
  19.                     "seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, is_real, " .
  20.                     "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)" .
  21.                 "VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .
  22.                     "'$brand_id', '$shop_price', '$logi_cost', '$market_price', '$is_promote','$promote_price', ".
  23.                     "'$promote_start_date', '$promote_end_date', '$goods_img', '$index_img', '$goods_thumb', '$original_img', ".
  24.                     "'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".
  25.                     " '$warn_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', 0, '$is_on_sale', '$is_alone_sale', $is_shipping, ".
  26.                     " '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$code', '$rank_integral', '$goods_provincestr', '$goods_citystr', '$virtual_buy', '$shipping_id')";
  27.         }
  28.     }    else
  29.     {        /* 如果有上传图片,删除原来的商品图 */
  30.         $sql = "SELECT goods_thumb, goods_img, index_img, original_img " .
  31.                     " FROM " . $ecs->table('goods') .
  32.                     " WHERE goods_id = '$_REQUEST[goods_id]'";        $row = $db->getRow($sql);        if ($proc_thumb && $goods_img && $row['goods_img'] && !goods_parse_url($row['goods_img']))
  33.         {
  34.             @unlink(ROOT_PATH . $row['goods_img']);
  35.             @unlink(ROOT_PATH . $row['original_img']);
  36.         }        if ($proc_thumb && $goods_thumb && $row['goods_thumb'] && !goods_parse_url($row['goods_thumb']))
  37.         {
  38.             @unlink(ROOT_PATH . $row['goods_thumb']);
  39.         }        
  40.         if ($index_img && $row['index_img'] && !goods_parse_url($row['index_img']))
  41.         {
  42.             @unlink(ROOT_PATH . $row['index_img']);
  43.         }        $sql = "UPDATE " . $ecs->table('goods') . " SET " .
  44.                 "goods_name = '$_POST[goods_name]', " .
  45.                 "goods_name_style = '$goods_name_style', " .
  46.                 "goods_sn = '$goods_sn', " .
  47.                 "cat_id = '$catgory_id', " .
  48.                 "brand_id = '$brand_id', " .
  49.                 "shop_price = '$shop_price', " .
  50.                 "logi_cost = '$logi_cost', " .
  51.                 "market_price = '$market_price', " .
  52.                 "is_promote = '$is_promote', " .
  53.                 "promote_price = '$promote_price', " .
  54.                 "promote_start_date = '$promote_start_date', " .
  55.                 "suppliers_id = '$suppliers_id', " .
  56.                 "province = '$goods_provincestr', " .
  57.                 "city = '$goods_citystr', " .
  58.                 "virtual_buy = '$virtual_buy', " .
  59.                 "shipping_id = '$shipping_id', " .
  60.                 "promote_end_date = '$promote_end_date', ";        /* 如果有上传图片,需要更新数据库 */
复制代码



2.3 后台添加/编辑商品 实现绑定配送方式"admin/goods_info.htm"
  1.           运费模板          {$lang.select_please}
  2.         {foreach from=$shipping_list item=shipping}                {$shipping.shipping_name}              {/foreach} {$lang.require_field}
复制代码
在品牌下面,增加绑定运费模板。效果如下:


3、前台商品详情调用设置好的配送方式

      以主题default为例,增加新文件:
          1、chrome.js (themes/default/js)
          2、icon_2.jpg (themes/default/images)

goods.php页面商品显示部分加入调用代码
  1. /***** 商品页按地区显示运费 ***********************************************************************/
  2. $shippings = array(); $res = $db->GetAll("SELECT shipping_name, shipping_id FROM ecs_shipping WHERE shipping_id=".$goods['shipping_id']); foreach ($res as $value)
  3. { $areas = array(); $res1 = $db->GetAll("SELECT * FROM ecs_shipping_area WHERE shipping_id = $value[shipping_id]"); foreach ($res1 as $area)
  4. { $configure = unserialize($area['configure']); if (is_array($configure))
  5. { foreach ($configure as $c)
  6. { if ($c['name'] == 'base_fee')
  7. { $price = $c['value'];
  8. }
  9. }
  10. } $sql = "SELECT a.region_id, r.region_name ".
  11. "FROM ".$ecs->table('area_region')." AS a, ".$ecs->table('region'). " AS r ".
  12. "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))
  13. { $value['areas'][$arr['region_name']] = $price;
  14. }
  15. } $shippings[] = $value;
  16. } $res = $db->GetAll("SELECT region_id,region_name FROM ecs_region WHERE parent_id = 1"); if($goods['shipping_id'] == 6)
  17. { $current_region = '广东';   //默认显示广东省
  18. $smarty->assign('current_region',   $current_region);
  19. $smarty->assign('current_price',   '7');
  20. } foreach ($res as $value)
  21. { $row = array(); foreach ($shippings as $a => $shipping)
  22. { if ($shipping['areas'])
  23. { foreach ($shipping['areas'] as $key => $price)
  24. { if ($key == $value['region_name'])
  25. { $row[$a]['shipping_price'] = $price;
  26. }
  27. }
  28. } if ($row[$a]['shipping_price'] > 0)
  29. { $row[$a]['shipping_name'] = $shipping['shipping_name']; $value['shippings'] = $row;
  30. }
  31. } if ($value['shippings']) $regions[] = $value;
  32. } $smarty->assign('regions',              $regions); /****************************************************************************/
复制代码


goods.dwt  加在需要显示运费的地方
  1.   {foreach from=$regions key=key item=value}
  2. {if $key == 0} 至 {$current_region}: {foreach from=$value.shippings item=shipping}
  3. {$shipping.shipping_name}{$current_price}元  
  4. {/foreach}   {/if}
  5. {/foreach}  {foreach from=$regions item=value} {$value.region_name} {/foreach}
复制代码


前台显示最终效果图,默认广东省


4、结算流程中,根据配送地址计算运费

4.1 重写“include/lib_order.php”中last_shipping_and_payment函数。多个商品,不同配送方式,调用配送方式ID,以最贵配送方式计算。买家可以找客服进行,运费改价。



  1. /**
  2. * 获得上一次用户采用的支付和配送方式
  3. *
  4. * @access  public
  5. * @return  void */function last_shipping_and_payment()
  6. {    $sql = "SELECT shipping_id, pay_id " .
  7.             " FROM " . $GLOBALS['ecs']->table('order_info') .
  8.             " WHERE user_id = '$_SESSION[user_id]' " .
  9.             " ORDER BY order_id DESC LIMIT 1";    $row = $GLOBALS['db']->getRow($sql);    /* LONGHTML 获得购物车中商品 运费模板最大值 */
  10.     $sql = "SELECT DISTINCT max(g.shipping_id) as  shipping_id " .
  11.             " FROM " . $GLOBALS['ecs']->table('cart') ." AS c ".
  12.             " LEFT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g ON c.goods_id = g.goods_id" .
  13.             " WHERE c.`session_id` =  '" . SESS_ID . "'".
  14.             " AND c.`extension_code` !=  'package_buy' ";    $shipping_id = $GLOBALS['db']->getOne($sql);    $row['shipping_id'] = $shipping_id;    // END
  15.     if (empty($row))
  16.     {        /* 如果获得是一个空数组,则返回默认值 */
  17.         $row = array('shipping_id' => 0, 'pay_id' => 0);
  18.     }    return $row;
  19. }
复制代码


4.2  flow.php购物流程checkout,done步骤,调用商品绑定的配送方式
  1. * 对是否允许修改购物车赋值 */
  2.    if ($flow_type != CART_GENERAL_GOODS || $_CFG['one_step_buy'] == '1')
  3.    {       $smarty->assign('allow_edit_cart', 0);
  4.    }   else
  5.    {       $smarty->assign('allow_edit_cart', 1);
  6.    }// LONGHTML 最大值的运费模板 $arr = last_shipping_and_payment();$_SESSION['flow_order']['shipping_id'] = $arr['shipping_id'];$smarty->assign('select_shipping_id', $arr['shipping_id']);// END
复制代码



  1. /**
  2. * 取得已安装的配送方式
  3. * @return  array   已安装的配送方式*/function shipping_list()
  4. {    $sql = 'SELECT shipping_id, shipping_name ' .
  5.             'FROM ' . $GLOBALS['ecs']->table('shipping') .
  6.             ' WHERE enabled = 1';    return $GLOBALS['db']->getAll($sql);
  7. }0
复制代码

将themes/default/flow.dwt配送方式隐藏掉
  1. /**
  2. * 取得已安装的配送方式
  3. * @return  array   已安装的配送方式*/function shipping_list()
  4. {    $sql = 'SELECT shipping_id, shipping_name ' .
  5.             'FROM ' . $GLOBALS['ecs']->table('shipping') .
  6.             ' WHERE enabled = 1';    return $GLOBALS['db']->getAll($sql);
  7. }1
复制代码


5、经过上面多处增加/修改,测试一下运行效果。

广东  首重10KG 7元,续重0.7元/KG





最新评论

MableMok12 发表于 2022-7-8 08:38
html5音乐网站源码

轻源码让程序更轻更快

QingYuanMa.com

工作时间 周一至周六 8:00-17:30

侵权处理

客服QQ点击咨询

关注抖音号

定期抽VIP

Copyright © 2016-2021 https://www.171739.xyz/ 滇ICP备13200218号

快速回复 返回顶部 返回列表