ECSHOP二次开发-给商品增加一个新字段-站长杂谈下载

ECSHOP二次开发--给商品增加一个新字段

开通本站Svip会员,全站资源免费下
在ECSHOP二次开发工作中,经常碰到一些ECSHOP高级使用者问我,如何给商品增加一个新字段,来录入一些新的内容。3 ?  K$ t. \: B& ~, H
下面我们结合ecshop后台“商品编辑”、“商品录入”来谈谈如何给ecshop商品增加一个新字段,假设我们将这个新字段命名为 other_col
. f5 Z2 U2 U+ @: B4 w8 L 7 G' w$ H1 ?2 C, O* h
1、首先要修改数据表结构,给表 ecs_goods 增加新字段:other_col,
* s- g# ^" O. {: X" @0 I5 \       进入ECSHOP后台 》数据库管理 》SQL查询,输入下面SQL语句,提交。注意如果你的数据表前缀不是ecs_ 请自行修改之
     alter table ecs_goods add column other_col varchar(64);  {# S6 {0 y4 q9 N) J8 _
2 q7 d' ~' ?  X2 g7 `
2、在ecshop后台的admin\templates\goods_info.htm中增加以下代码.
    <tr>4 f( n( a( d1 q4 {+ I6 D5 s& e
            <td class="label">自定义字段</td>9 q& n) g9 z$ Y! B. r
            <td><input type="text" name="other_col" value="{$goods.other_col}" size="20"/>
8 o' r/ E2 ?9 m) F6 h            </td>
# R4 F8 X. p; e7 x  E: ?1 X* ~          </tr>: N9 ]  w' f" o7 F" E' g8 E' g( c& L

% J# S$ E9 J' A. T; H0 b3、在admin/goods.php的elseif ($_REQUEST['act'] == 'insert' || $_REQUEST['act'] == 'update')里面增加以下程序
     $sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .
# A( R5 c3 g* p7 I                    "cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " ." }* G5 O& V- S; V  U3 {, }0 }
                    "promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " .; {1 L& E7 y" ^# w: D; }
                    "seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, " .
1 l7 f, [/ n; n9 x3 O! j                    "is_on_sale, is_alone_sale, is_shipping, goods_desc, add_time, last_update, goods_type, rank_integral, suppliers_id,other_col)" .
1 }/ G: L' O3 Z                "VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .
6 V+ f6 I; |% t. E2 S# S1 [                    "'$brand_id', '$shop_price', '$market_price', '$is_promote','$promote_price', ".' x9 E& t3 q8 u* _8 i: e5 b
                    "'$promote_start_date', '$promote_end_date', '$goods_img', '$goods_thumb', '$original_img', ".# [! ~  j3 ~- A8 I, j) @; G9 A
                    "'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".+ U, S$ ~2 W3 D
                    " '$warn_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', '$is_on_sale', '$is_alone_sale', $is_shipping, ".
8 k! z1 l$ G& A# x8 y4 q- B                    " '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$rank_integral', '$suppliers_id','$_POST[other_col]')";
。。。。。。。。
3 z4 A5 m  _6 J; A  [0 r: t。。。。。。。。; q' P1 @' n% M- C! n/ }( r3 Z6 l; Q" E
" S/ h( u$ T+ Q& y
" other_col = '$_POST[other_col]', " .
      这样我们就完成了在ECSHOP后台录入和修改新字段的功能了。
下面再来说一下前台调用的方法:
. u9 m7 f( z/ X; ]     
) I1 [5 ]0 ]* q6 U/ [6 u0 y调用也很简单,直接在模板文件或者  lbi文件里 这么调用即可 {$goods.other_col}

6 s: b% P5 Q5 n# }% [

全部评论 0

您需要登录后才可以回帖 立即登录
登录
0
0
0
返回顶部