Zen-Cart给产品添加新字段

转载出处:http://www.qq2000.info/post/155.html


在网上找到一篇英文文章,为了方便,特翻译成中文。
原文地址:http://www.zen-cart.com/forum /showthread.php?t=57924

这篇文章介绍怎么样为普通产品添加一个新属性。
1、首先考虑你要添加一个什么样的 属性到你的产品,在这个例子中添加两个属性:[guarantee-time]和[color]。

2、在数据库管理界面 (如:phpmyadmin)中找到表[products],或者表的前缀加[products],为这个表添加两个字段: [products_guarantee] 和[products_color] :

 
ALTER TABLE `zencart_products` ADD `products_guarantee` INT NOT NULL , ADD `products_color` VARCHAR ( 32 ) NOT NULL ;

3、编辑文件 [collect_info.php](在目录/admin/includes/modules/product/下)
(1)在最开始的地方有一 个变量参数设置,添加你的字段到它们的最后:

 
'products_guarantee' => '0' , 'products_color' => '' );

(2) 在下边有一个数据库查询:

 
set [$product = $db-> Execute ("...]

添加你的字段在 [from ...] 部分的前边,并且字段前添加[p.]:

 
select ......., p.products_guarantee, p.products_color from ....

(3)现在添加输入框到产品表单中(在450行附近,具体位置自己 看情况定):

 
< TR >
< TD class = main >Guarantee Time (in months)</ TD >
< TD class = main ><? php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . zen_draw_input_field('products_guarantee', $pInfo->products_guarantee, zen_set_field_length(TABLE_PRODUCTS, 'products_guarantee')); ?></ TD >
</ TR >
< TR >
< TD class = main >Color</ TD >
< TD class = main ><? php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . zen_draw_input_field('products_color', $pInfo->products_color, zen_set_field_length(TABLE_PRODUCTS, 'products_color')); ?></ TD >
</ TR >

4、 编辑文件 [preview_info.php] (在目录 /admin/includes/modules/product/下)
在第10行 左右,找到变量[$product]的定义. 像上边3.2中的一样添加查询字段:

 
select ......., p.products_guarantee, p.products_color from ....

5、 编辑 [update_product.php] (在目录/admin/includes/modules/下)
在20行左右找 到$sql_data_array变量那个的定义. 在最后一行的[);] 前边添加新字段.

 
$sql_data_array = .......... 'products_guarantee' => zen_db_prepare_input( $_POST [ 'products_guarantee' ]), 'products_color' => zen_db_prepare_input( $_POST [ 'products_color' ]) );

6、 编辑 [main_template_vars.php] (在目录/includes/modules/pages/product_info/下)
在 第40行左右找到变量[$sql]的定义,像3.2中一样添加新字段的查询:

 
select ......., p.products_guarantee, p.products_color from ....

7、 最后一步:在产品信息中显示。
编辑[tpl_product_info_display.php'](在目录/includes /templates/你的模板/templates/下)
你可以把下边的代码添加到你认为合适的显示位置

 
echo $product_info ->fields[ 'products_guarantee' ];
echo $product_info ->fields[ 'products_color' ];

OK,希望你一切顺利!

我 已经在我的网店下添加了一个字段,用于保存该商品在淘宝店的地址,如果在商品发布时,添加了淘宝地址,在页面上就会显示一行文字,并连接到淘宝店的地址。

 

 

------------ 摘自:BOSSMA [blog.bossma.cn]


转载出处:http://www.qq2000.info/post/155.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值