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

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

来自版块: 站长杂谈发表于: 2015-8-9 00:22:37
50184
0
如本资源下载地址失效,请点击此处进行反馈
开通本站Svip会员,全站资源免费下
在ECSHOP二次开发工作中,经常碰到一些ECSHOP高级使用者问我,如何给商品增加一个新字段,来录入一些新的内容。' \( l7 O- T0 V
下面我们结合ecshop后台“商品编辑”、“商品录入”来谈谈如何给ecshop商品增加一个新字段,假设我们将这个新字段命名为 other_col8 M4 i7 e1 D1 j5 K3 c5 g# U
8 n0 T0 h  i- J$ l# h
1、首先要修改数据表结构,给表 ecs_goods 增加新字段:other_col,- h% |0 _% @/ T+ I# H% T
       进入ECSHOP后台 》数据库管理 》SQL查询,输入下面SQL语句,提交。注意如果你的数据表前缀不是ecs_ 请自行修改之
     alter table ecs_goods add column other_col varchar(64);
$ p2 M. ?7 D7 ~( `. m8 z/ m
. R( h( D: Z9 h/ b) _' Y- }8 X2、在ecshop后台的admin\templates\goods_info.htm中增加以下代码.
    <tr>3 \! T! j$ I2 \
            <td class="label">自定义字段</td>
# V9 O, V. r# x8 E7 `! E6 Q            <td><input type="text" name="other_col" value="{$goods.other_col}" size="20"/>
# _/ Q  m+ E5 P7 h# q& E0 m$ x            </td>
1 Q( M1 c& K6 N- v7 u) \          </tr>
. U2 q) @" i; o! r* d- e5 r1 F
8 a! s/ H! h. q' K: A/ K0 t$ s3、在admin/goods.php的elseif ($_REQUEST['act'] == 'insert' || $_REQUEST['act'] == 'update')里面增加以下程序
     $sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .( k0 U1 g" x7 B# D& ]" _
                    "cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " .
' n( r  j$ F1 Z9 B3 _" p0 S0 H# F9 Z# v                    "promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " .# u7 {6 ^. \, M1 Z# c
                    "seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, " .
8 b: U# D) s$ ]" {  Z9 y& f6 k                    "is_on_sale, is_alone_sale, is_shipping, goods_desc, add_time, last_update, goods_type, rank_integral, suppliers_id,other_col)" .* |; O  T8 T5 V4 G* _/ _: s
                "VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .3 N! {- W1 ~6 J. d- z) u
                    "'$brand_id', '$shop_price', '$market_price', '$is_promote','$promote_price', ".) ^' {6 I# ]7 Z- l6 V$ j! f
                    "'$promote_start_date', '$promote_end_date', '$goods_img', '$goods_thumb', '$original_img', ".+ A  q! P6 F4 z3 G9 f& m
                    "'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".; O0 G  m9 b6 e: }( X' Y! f  G
                    " '$warn_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', '$is_on_sale', '$is_alone_sale', $is_shipping, ".
( F+ R0 r- J" f. d  u                    " '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$rank_integral', '$suppliers_id','$_POST[other_col]')";
。。。。。。。。$ p; u, ?/ F& m
。。。。。。。。; Y! u9 m' u, U( C$ t0 [7 j
. C' u" P+ c- r: b$ v. U) z; d! V
" other_col = '$_POST[other_col]', " .
      这样我们就完成了在ECSHOP后台录入和修改新字段的功能了。
下面再来说一下前台调用的方法:8 S( r& e* W: R! a- q: K' @
     
% j. i; M  J" O# `/ q% |0 {0 t调用也很简单,直接在模板文件或者  lbi文件里 这么调用即可 {$goods.other_col}

; A& F8 [4 V7 N! i

全部评论 0

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