ecshop开发需求:
1. 每个登录的用户在购物过程中的商品列表页、商品详细页、购物车都可以对商品进行批注;
2. 要求1中的批注会显示在订单中每个商品项中;
3. 用户每次登陆之后清除上次的批注。
修改方法:
【1】增加两个表:
-- ----------------------------
-- Table structure for `order_comment`
-- ----------------------------
DROP TABLE IF EXISTS `order_comment`;
CREATE TABLE `order_comment` (
`order_id` mediumint(8) NOT NULL,
`goods_id` mediumint(8) NOT NULL,
`goods_comment` varchar(500) DEFAULT NULL,
PRIMARY KEY (`order_id`,`goods_id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;
-- ----------------------------
-- Table structure for `goods_comment`
-- ----------------------------
DROP TABLE IF EXISTS `goods_comment`;
CREATE TABLE `goods_comment` (
`goods_id` mediumint(8) NOT NULL,
`user_id` mediumint(8) NOT NULL,
`goods_comment` varchar(500) DEFAULT NULL,
PRIMARY KEY (`goods_id`,`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;
【2】themes/default/library/goods_list.lbi文件中:
<a href="javascript:;" id="compareLink" onClick="Compare.add({$goods.goods_id},'{$goods.goods_name|escape:"html"}','{$goods.type}')" class="f6">{$lang.compare}</a>
后边增加:
<!--{if $smarty.session.user_id}-->
{$lang.my_goods_comment}:<textarea onclick="addGoodsComment(this, {$goods.goods_id})" style="width:90%;">{$goods.goods_comment}</textarea>
<br />
<!--{/if}-->
【3】themes/default/user_transaction.dwt文件中:
<th width="23%" align="center" bgcolor="#ffffff">{$lang.goods_name}</th>
<th width="29%" align="center" bgcolor="#ffffff">{$lang.goods_attr}</th>
后面增加:
<!--{if $smarty.session.user_id}-->
<th bgcolor="#ffffff">{$lang.my_goods_comment}</th>
<!--{/if}-->
在:
<td align="left" bgcolor="#ffffff">{$goods.goods_attr|nl2br}</td>
后边增加:
<!--{if $smarty.session.user_id}-->
<td align="right" bgcolor="#ffffff">
{$goods.goods_comment}
</td>
<!--{/if}-->
【4】themes/default/goods.dwt文件中:
<li class="padd">
<a href="javascript:addToCart({$goods.goods_id})"><img src="images/bnt_cat.gif" /></a>
<a href="javascript:collect({$goods.goods_id})"><img src="images/bnt_colles.gif" /></a>
<!-- {if $affiliate.on} -->
<a href="user.php?act=affiliate&goodsid={$goods.goods_id}"><img src='images/bnt_recommend.gif'></a>
<!-- {/if} -->
</li>
后边增加:
<li>
<!--{if $smarty.session.user_id}-->
{$lang.my_goods_comment}:<textarea onclick="addGoodsComment(this, {$goods.goods_id})" style="width:90%;">{$goods.goods_comment}</textarea>
<!--{/if}-->
</li>
【5】themes/default/flow.dwt文件中:
<th bgcolor="#ffffff">{$lang.goods_name}</th>
<!-- {if $show_goods_attribute eq 1} 显示商品属性 -->
<th bgcolor="#ffffff">{$lang.goods_attr}</th>
<!-- {/if} -->
后边增加:
<!--{if $smarty.session.user_id}-->
<th bgcolor="#ffffff">{$lang.my_goods_comment}</th>
<!--{/if}-->
在:
<!-- {if $show_goods_attribute eq 1} 显示商品属性 -->
<td bgcolor="#ffffff">{$goods.goods_attr|nl2br}</td>
<!--{/if}-->
后边增加:
<!--{if $smarty.session.user_id}-->
<td align="right" bgcolor="#ffffff">
<textarea onclick="addGoodsComment(this, {$goods.goods_id})" style="width:90%;">{$goods.goods_comment}</textarea>
</td>
<!-- {/if} -->
在:
<th bgcolor="#ffffff">{$lang.goods_name}</th>
<th bgcolor="#ffffff">{$lang.goods_attr}</th>
后边增加:
<!--{if $smarty.session.user_id}-->
<th bgcolor="#ffffff">{$lang.my_goods_comment}</th>
<!--{/if}-->
在:
<!-- {if $goods.is_shipping} -->(<span style="color:#FF0000">{$lang.free_goods}</span>)<!-- {/if} -->
</td>
<td bgcolor="#ffffff">{$goods.goods_attr|nl2br}</td>
后边增加:
<!--{if $smarty.session.user_id}-->
<td align="right" bgcolor="#ffffff">
<textarea onclick="addGoodsComment(this, {$goods.goods_id})" style="width:90%;">{$goods.goods_comment}</textarea>
</td>
<!--{/if}-->
【6】languages/zh_cn/admin/common.php文件中增加:
$_LANG['my_goods_comment'] = '批注';
【7】languages/zh_cn/common.php文件中增加:
$_LANG['my_goods_comment'] = '批注';
【8】js/common.js文件中增加:
/*
* 将用户对商品的批注写到数据库中
*/
function addGoodsComment(obj, goodsId)
{
/* 保存原始的内容 */
var orgComment = obj.value;
/* 编辑区失去焦点的处理函数 */
obj.onblur = function(e)
{
var newComment = obj.value;
if (newComment != orgComment)
{
res = Ajax.call("./goods.php?is_ajax=1", "act=edit_goods_comment&val=" + encodeURIComponent(Utils.trim(newComment)).toJSONString() + "&id=" +goodsId, null, "POST", "JSON", false);
if (res.message)
{
alert(res.message);
}
}
}
}
【9】includes/lib_order.php文件中:
$sql = "SELECT rec_id, goods_id, goods_name, goods_sn, market_price, goods_number, " .
"goods_price, goods_attr, is_real, parent_id, is_gift, " .
"goods_price * goods_number AS subtotal, extension_code " .
"FROM " . $GLOBALS['ecs']->table('order_goods') .
" WHERE order_id = '$order_id'";
改为:
$sql = "SELECT rec_id, order_goods.goods_id, goods_name, goods_sn, market_price, goods_number, " .
"goods_price, goods_attr, is_real, parent_id, is_gift, " .
"goods_price * goods_number AS subtotal, extension_code, oc.goods_comment " .
新闻热点
疑难解答