实现Ecshop商品跳到淘宝、京东等的购买链接
2024-08-08 14:04:09 216人阅读
今天简单的实现了一下ecshop商品导出到第三方的购买链接功能。
大致思路是给商品添加一个buy_link的text字段,存为json结构,然后通过json解析输出到商品购买页面
1.添加字段
增加购买链接字段,执行sql语句:
1 | ALTER TABLE `ecs_goods` ADD `buy_link` TEXT NULL AFTER `goods_thumb` ; |
2.增加商品发布表单项
随意增加
2 | <td class = "label" >购买链接</td> |
3 | <td><textarea name= "buy_link" cols= "40" rows= "3" >{ $goods .buy_link}</textarea></br> |
4 | 使用了简单json结构,请严格按照格式填写(如:{ ‘taobao‘ : ‘http://‘ , ‘360buy‘ : ‘http://‘ },</br>分别代表淘宝店和京东店内的购买连接) |
到/admin/templates/goods_info.htm,我增加在第258行下面(即,第三个table最后注意不要破坏table结构)
后台商品编辑页面多出了一个项目
3.增加读取数据
因为涉及到数据更新,应该先给表单填写初始值。在/admin/goods.php 446行下增加
1 | $smarty ->assign( ‘buy_link‘ , $goods [ ‘buy_link‘ ]); |
4.增加发布商品存库
编辑/admin/goods.php页面821开始。取得表单传值buy_link,并在insert语句中增加中字段buy_link。可以直接修改为
1 | $goods_thumb = ( empty ( $goods_thumb ) && isset( $_POST [ ‘auto_thumb‘ ]))? $goods_img : $goods_thumb ; |
2 | $buy_link = empty ( $_POST [ ‘buy_link‘ ]) ? ‘‘ : trim( $_POST [ ‘buy_link‘ ]); |
9 | $sql = "INSERT INTO " . $ecs ->table( ‘goods‘ ) . " (goods_name, goods_name_style, goods_sn, " . |
10 | "cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " . |
11 | "promote_start_date, promote_end_date, goods_img, goods_thumb, buy_link, original_img, keywords, goods_brief, " . |
12 | "seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, " . |
13 | "is_on_sale, is_alone_sale, is_shipping, goods_desc, add_time, last_update, goods_type, rank_integral, suppliers_id)" . |
14 | "VALUES (‘$_POST[goods_name]‘, ‘$goods_name_style‘, ‘$goods_sn‘, ‘$catgory_id‘, " . |
15 | "‘$brand_id‘, ‘$shop_price‘, ‘$market_price‘, ‘$is_promote‘,‘$promote_price‘, " . |
16 | "‘$promote_start_date‘, ‘$promote_end_date‘, ‘$goods_img‘, ‘$goods_thumb‘, ‘$buy_link‘, ‘$original_img‘, " . |
17 | "‘$_POST[keywords]‘, ‘$_POST[goods_brief]‘, ‘$_POST[seller_note]‘, ‘$goods_weight‘, ‘$goods_number‘," . |
18 | " ‘$warn_number‘, ‘$_POST[integral]‘, ‘$give_integral‘, ‘$is_best‘, ‘$is_new‘, ‘$is_hot‘, ‘$is_on_sale‘, ‘$is_alone_sale‘, $is_shipping, " . |
19 | " ‘$_POST[goods_desc]‘, ‘" . gmtime() . "‘, ‘" . gmtime() . "‘, ‘$goods_type‘, ‘$rank_integral‘, ‘$suppliers_id‘)" ; |
23 | $sql = "INSERT INTO " . $ecs ->table( ‘goods‘ ) . " (goods_name, goods_name_style, goods_sn, " . |
24 | "cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " . |
25 | "promote_start_date, promote_end_date, goods_img, goods_thumb, buy_link, original_img, keywords, goods_brief, " . |
26 | "seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, is_real, " . |
27 | "is_on_sale, is_alone_sale, is_shipping, goods_desc, add_time, last_update, goods_type, extension_code, rank_integral)" . |
28 | "VALUES (‘$_POST[goods_name]‘, ‘$goods_name_style‘, ‘$goods_sn‘, ‘$catgory_id‘, " . |
29 | "‘$brand_id‘, ‘$shop_price‘, ‘$market_price‘, ‘$is_promote‘,‘$promote_price‘, " . |
30 | "‘$promote_start_date‘, ‘$promote_end_date‘, ‘$goods_img‘, ‘$goods_thumb‘, ‘$buy_link‘, ‘$original_img‘, " . |
31 | "‘$_POST[keywords]‘, ‘$_POST[goods_brief]‘, ‘$_POST[seller_note]‘, ‘$goods_weight‘, ‘$goods_number‘," . |
32 | " ‘$warn_number‘, ‘$_POST[integral]‘, ‘$give_integral‘, ‘$is_best‘, ‘$is_new‘, ‘$is_hot‘, 0, ‘$is_on_sale‘, ‘$is_alone_sale‘, $is_shipping, " . |
33 | " ‘$_POST[goods_desc]‘, ‘" . gmtime() . "‘, ‘" . gmtime() . "‘, ‘$goods_type‘, ‘$code‘, ‘$rank_integral‘)" ; |
,这样 增加商品时就能指定buy_link了
5.增加修改商品存库
在/admin/goods.php 901 行上的sql拼接上增加
1 | "buy_link = ‘$buy_link‘, " . |
则变为
1 | $sql .= "buy_link = ‘$buy_link‘, " . |
2 | "keywords = ‘$_POST[keywords]‘, " . |
3 | "goods_brief = ‘$_POST[goods_brief]‘, " . |
4 | "seller_note = ‘$_POST[seller_note]‘, " . |
5 | "goods_weight = ‘$goods_weight‘," . |
6 | "goods_number = ‘$goods_number‘, " . |
7 | "warn_number = ‘$warn_number‘, " . |
8 | "integral = ‘$_POST[integral]‘, " . |
9 | "give_integral = ‘$give_integral‘, " . |
10 | "rank_integral = ‘$rank_integral‘, " . |
11 | "is_best = ‘$is_best‘, " . |
12 | "is_new = ‘$is_new‘, " . |
13 | "is_hot = ‘$is_hot‘, " . |
14 | "is_on_sale = ‘$is_on_sale‘, " . |
15 | "is_alone_sale = ‘$is_alone_sale‘, " . |
16 | "is_shipping = ‘$is_shipping‘, " . |
17 | "goods_desc = ‘$_POST[goods_desc]‘, " . |
18 | "last_update = ‘" . gmtime() . "‘, " . |
19 | "goods_type = ‘$goods_type‘ " . |
20 | "WHERE goods_id = ‘$_REQUEST[goods_id]‘ LIMIT 1" ; |
由此,数据入库基本完成,现在做模版赋值。
6.模版赋值
goods_info函数已经读取出来所有数据,因此直接修改/goods.php( 注:是根目录下的),在197行下增加
5 | if ( is_null (json_decode( $goods [ ‘buy_link‘ ]))){ |
7 | $smarty ->assign( ‘buy_link‘ , $goods [ ‘buy_link‘ ]); |
7.模版读取
修改商品详情模版,如/themes/default/goods.dwt。397行下增加
3 | < script type = "text/javascript" language = "javascript" > |
8 | Jbuylink = eval("{$buy_link}"); |
9 | for(i=0;i< Jbuylink.length ;i++){ |
10 | text +=‘<a href = "‘+Jbuylink[i].url+‘" target = "_blank" >‘+Jbuylink[i].text+‘</ a > ‘; |
12 | document.write("< br />"+text); |
ok,功能完成。
下面简单测试下:编辑任意商品buy_link属性为[{text:‘淘宝购买‘,url:‘http://taobao.com‘},{text:‘京东购买‘,url:‘http://360buy.com?p=89899‘}] 保存,查看页面,如图:
商品导出连接
由此,已经能够读取到导出链接了
第4步中的内容改为
2 | < td class = "label" >购买链接</ td > |
3 | < td >< textarea name = "buy_link" cols = "40" rows = "3" >{$goods.buy_link}</ textarea ></ br > |
4 | 请严格按照格式填写(如:[{text:‘淘宝购买‘,url:‘http://taobao.com‘},{text:‘京东购买‘,url:‘http://360bu.com‘}] </ br >分别代表淘宝店和京东店内的购买连接) |
实现Ecshop商品跳到淘宝、京东等的购买链接
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉:
投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。