ecshop運(yùn)費(fèi)配送方式仿淘寶地區(qū)運(yùn)費(fèi)模板功能開發(fā)
時(shí)間: 2024-02-25 10:43
閱讀: 次
作者:素材無憂網(wǎng)
ECSHOP運(yùn)費(fèi)配送方式仿淘寶地區(qū)運(yùn)費(fèi)模板功能開發(fā)
目錄:
1、Ecshop后臺(tái)配送方式創(chuàng)建
2、商品綁定配送方式的運(yùn)費(fèi)模板
2.1 數(shù)據(jù)表"ecs_goods"增加一個(gè)字段,執(zhí)行下面SQL語句:
2.2 后臺(tái)添加/編輯 商品 調(diào)出已經(jīng)安裝配送方式 "admin/ goods.php ",將此shipping_list函數(shù)添加到goods.php最末處。
2.3 后臺(tái)添加/編輯商品 實(shí)現(xiàn)綁定配送方式"admin/goods_info.htm"
3、前臺(tái)商品詳情調(diào)用設(shè)置好的配送方式
4、結(jié)算流程中,根據(jù)配送地址計(jì)算運(yùn)費(fèi)
4.1 重寫"include/lib_order.php"中l(wèi)ast_shipping_and_payment函數(shù)。多個(gè)商品,不同配送方式,調(diào)用配送方式ID,以最貴配送方式計(jì)算。買家可以找客服進(jìn)行,運(yùn)費(fèi)改價(jià)。
5、經(jīng)過上面多處增加/修改,測試一下運(yùn)行效果。
淘寶網(wǎng)(Taobao)購物的寶貝詳情頁面,可以針對(duì)不同地區(qū)顯示不同運(yùn)費(fèi),運(yùn)費(fèi)由后臺(tái)設(shè)定;結(jié)算時(shí)間,按重量、件數(shù)計(jì)算運(yùn)費(fèi)。Ecshop本身有配送方式插件,已有多家物流公司插件,例如:順豐快遞、申通快遞、圓通快遞等。本文介紹如何實(shí)現(xiàn)按地區(qū)顯示運(yùn)費(fèi),并且讓每個(gè)商品綁定運(yùn)費(fèi)模板。
1、Ecshop后臺(tái)配送方式創(chuàng)建
進(jìn)入Ecshop后臺(tái)"系統(tǒng)設(shè)置-->配送方式",將"順豐快遞"改名稱為"糧食快遞",配送ID號(hào)為6。
2、商品綁定配送方式的運(yùn)費(fèi)模板 2.1 數(shù)據(jù)表"ecs_goods"增加一個(gè)字段,執(zhí)行下面SQL語句:
ALTER TABLE `ecs_goods` ADD `shipping_id` MEDIUMINT(9) NOT NULL DEFAULT '6';
2.2 后臺(tái)添加/編輯 商品 調(diào)出已經(jīng)安裝配送方式 "admin/ goods.php ",將此shipping_list函數(shù)添加到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());"增加調(diào)用代碼
// LONGHTML 增加運(yùn)費(fèi)模板 $smarty->assign('shipping_list', shipping_list()); // END $smarty->assign('unit_list', get_unit_list());
在"/* 處理商品數(shù)據(jù) */"后面,增加POST過來的"shipping_id "表單值進(jìn)行賦值
/* 處理商品數(shù)據(jù) */ // LONGHTML 運(yùn)費(fèi)模板(新增,更新) $shipping_id = empty($_POST['shipping_id']) ? '0' : intval($_POST['shipping_id']); // END
最后一步是"插入/更新"商品時(shí),對(duì)"shipping_id"字段實(shí)現(xiàn)處理。直接替換掉下面代碼
/* 入庫 */ if ($is_insert) { if ($code == '') { $sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " . "cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " . "promote_start_date, promote_end_date, goods_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, shipping_id)" .//注意這里增加了一個(gè)字段 shipping_id "VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " . "'$brand_id', '$shop_price', '$market_price', '$is_promote','$promote_price', ". "'$promote_start_date', '$promote_end_date', '$goods_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', '$shipping_id' )";//注意這里增加了字段 shiping_id by uuecs.com } else { $sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " . "cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " . "promote_start_date, promote_end_date, goods_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,shipping_id)" .//注意這里增加了一個(gè)字段 shipping_id "VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " . "'$brand_id', '$shop_price', '$market_price', '$is_promote','$promote_price', ". "'$promote_start_date', '$promote_end_date', '$goods_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', '$shipping_id')";//注意這里增加了一個(gè)字段 shipping_id } } else { /* 如果有上傳圖片,刪除原來的商品圖 */ $sql = "SELECT goods_thumb, goods_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']); } $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', " . "market_price = '$market_price', " . "is_promote = '$is_promote', " . "promote_price = '$promote_price', " . "promote_start_date = '$promote_start_date', " . "suppliers_id = '$suppliers_id', " . // "province = '$goods_prov r', " . // "city = '$goods_citystr', " . // "virtual_buy = '$virtual_buy', " . "shipping_id = '$shipping_id', " .//注意這里新增的ecshop119.com "promote_end_date = '$promote_end_date', "; /* 如果有上傳圖片,需要更新數(shù)據(jù)庫 */
2.3 后臺(tái)添加/編輯商品 實(shí)現(xiàn)綁定配送方式"admin/goods_info.htm"
運(yùn)費(fèi)模板 | {$lang.require_field} |
在品牌下面,增加綁定運(yùn)費(fèi)模板。效果如下:
3、前臺(tái)商品詳情調(diào)用設(shè)置好的配送方式
以主題default為例,增加新文件:
1、chrome.js (themes/default/js)
2、icon_2.jpg (themes/default/images)
goods.php頁面商品顯示部分加入調(diào)用代碼
/***** 商品頁按地區(qū)顯示運(yùn)費(fèi) ***********************************************************************/ $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) //默認(rèn)快遞ID { $current_region = '廣東'; //默認(rèn)顯示廣東省 $smarty->assign('current_region', $current_region); $smarty->assign('current_price', '7'); //默認(rèn)價(jià)格 } 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 加在需要顯示運(yùn)費(fèi)的地方
{foreach from=$regions key=key item=value} {if $key == 0} {/if} {/foreach}