首页 > 网站 > 建站经验 > 正文

ecshop商品评论和咨询分开

2024-04-25 20:32:27
字体:
来源:转载
供稿:网友

 

笔者在测试过程中发现了一些细节的错误,笔者在这里纠正一下:

1:goods.dwt增加以下代码

<!-- #BeginLibraryItem "/library/comments1.lbi" --><!-- #EndLibraryItem -->

2:comments1.lbi内容为以下

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

{insert_scripts files='transport.js,utils.js'}

<div id="ECS_COMMENT1"> {* ECSHOP 提醒您:动态载入comments_list.lbi,显示评论列表和评论表单 *}{insert name='comments1' type=2 id=$id}</div>

3:comment_list1.lbi内容为以下

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<!--用户评论 START-->

<div>

<div>

<div style="background:url(images/bg006.jpg) no-repeat; height:25px; line-height:25px; margin-top:15px; color:#FFFFFF; padding-left:40px;">

<span>用户咨询</span>

({$lang.total}

<font color="#FFFFFF">{$pager.record_count}</font>

用户咨询)

</div>

<div style="height:1%;">

<ul>

<!-- {if $comments} -->

<!-- {foreach from=$comments item=comment} -->

<li>

<font><!-- {if $comment.username} -->{$comment.username|escape:html}<!-- {else} -->{$lang.anonymous}<!-- {/if} --></font> <font>( {$comment.add_time} )</font><br />

<img src="../images/stars{$comment.rank}.gif" alt="{$comment.comment_rank}" />

<p>{$comment.content}</p>

<!-- {if $comment.re_content} -->

<p><font>{$lang.admin_username}</font>{$comment.re_content}</p>

<!-- {/if} -->

</li>

<!-- {/foreach} -->

<!--{else}-->

<li>目前没有任何用户咨询</li>

<!--{/if}-->

</ul>

<!--翻页 start-->

<div id="pagebar">

<form name="selectPageForm" action="{$smarty.server.PHP_SELF}" method="get">

<!-- {if $pager.styleid eq 0 } -->

<div id="pager">

{$lang.pager_1}{$pager.record_count}{$lang.pager_2}{$lang.pager_3}{$pager.page_count}{$lang.pager_4} <span> <a href="{$pager.page_first}">{$lang.page_first}</a> <a href="{$pager.page_prev}">{$lang.page_prev}</a> <a href="{$pager.page_next}">{$lang.page_next}</a> <a href="{$pager.page_last}">{$lang.page_last}</a> </span>

<!--{foreach from=$pager.search key=key item=item}-->

<input type="hidden" name="{$key}" value="{$item}" />

<!--{/foreach}-->

</div>

<!--{else}-->

<!--翻页 start-->

<div id="pager">

<span style="margin-right:10px;">{$lang.total} <b>{$pager.record_count}</b> {$lang.user_comment_num}</span>

<!-- {if $pager.page_first} --><a href="{$pager.page_first}">1 ...</a><!-- {/if} -->

<!-- {if $pager.page_prev} --><a href="{$pager.page_prev}">{$lang.page_prev}</a><!-- {/if} -->

<!--{foreach from=$pager.page_number key=key item=item}-->

<!-- {if $pager.page eq $key} -->

<span>{$key}</span>

<!-- {else} -->

<a href="{$item}">[{$key}]</a>

<!-- {/if} -->

<!--{/foreach}-->

<!-- {if $pager.page_next} --><a href="{$pager.page_next}">{$lang.page_next}</a><!-- {/if} -->

<!-- {if $pager.page_last} --><a href="{$pager.page_last}">...{$pager.page_count}</a><!-- {/if} -->

<!-- {if $pager.page_kbd} -->

<!--{foreach from=$pager.search key=key item=item}-->

<input type="hidden" name="{$key}" value="{$item}" />

<!--{/foreach}-->

<kbd style="float:left; margin-left:8px; position:relative; bottom:3px;"><input type="text" name="page" size="3" /></kbd>

<!-- {/if} -->

</div>

<!--翻页 END-->

<!-- {/if} -->

</form>

<script type="Text/Javascript" language="JavaScript">

<!--

{literal}

function selectPage(sel)

{

sel.form.submit();

}

{/literal}

//-->

</script>

</div>

<!--翻页 END-->

<div></div>

<!--评论表单 start-->

<div>

<form action="javascript:;" method="post" name="commentForm1" id="commentForm1">

<table width="700" border="0" cellspacing="5" cellpadding="0">

<tr>

<td align="right">E-mail:</td>

<td>

<input type="text" name="email" id="email" maxlength="100" value="{$smarty.session.email|escape}"/>

</td>

</tr>

<tr>

<td align="right" valign="top">{$lang.comment_content}:</td>

<td>

<textarea name="content" style="height:50px; width:560px;"></textarea>

<input type="hidden" name="cmt_type" value="2" />

<input type="hidden" name="id" value="{$id}" />

</td>

</tr>

<tr>

<td colspan="2">

<!-- 判断是否启用验证码{if $enabled_captcha} -->

<div style="padding-left:15px; text-align:left; float:left;">

{$lang.comment_captcha}:<input type="text" name="captcha" style="width:50px; margin-left:5px;"/>

<img src="captcha.php?{$rand}" alt="captcha">

</div>

<!-- {/if} -->

<input name="" type="submit" value=" " style="border:none; background:url(../images/commentsBnt.gif); width:89px; height:21px; margin-right:8px;">

</td>

</tr>

</table>

</form>

</div>

<!--评论表单 end-->

</div>

</div>

</div>

<div></div>

<!--用户评论 END-->

<script type="text/javascript">

//<![CDATA[

{foreach from=$lang.cmt_lang item=item key=key}

var {$key} = "{$item}";

{/foreach}

{literal}

/**

* 提交评论信息

*/

function submitComment1(frm)

{

var cmt = new Object;

cmt.email = frm.elements['email'].value;

cmt.content = frm.elements['content'].value;

cmt.type = frm.elements['cmt_type'].value;

cmt.id = frm.elements['id'].value;

cmt.enabled_captcha = frm.elements['enabled_captcha'] ? frm.elements['enabled_captcha'].value : '0';

cmt.captcha = frm.elements['captcha'] ? frm.elements['captcha'].value : '';

cmt.rank = 5;

if (cmt.email.length > 0)

{

if (!(Utils.isEmail(cmt.email)))

{

alert(cmt_error_email);

return false;

}

}

else

{

alert(cmt_empty_email);

return false;

}

if (cmt.content.length == 0)

{

alert(cmt_empty_content);

return false;

}

if (cmt.enabled_captcha > 0 && cmt.captcha.length == 0 )

{

alert(captcha_not_null);

return false;

}

Ajax.call('comment1.php', 'cmt=' + cmt.toJS**tring(), commentResp**e1, 'POST', 'JSON'); 这里也有问题 注意** 根据具体函数进行修正

return false;

}

/**

* 处理提交评论的反馈信息

*/

function commentResp**e1(result) 此处有问题,这个函数的全名是:gotoPageResponse1

{

if (result.message)

{

alert(result.message);

}

if (result.error == 0)

{

var layer = document.getElementById('ECS_COMMENT1');

if (layer)

{

layer.innerHTML = result.content;

}

}

}

{/literal}

//]]>

</script>

注意他的cmp_type=2

<input type="hidden" name="cmt_type" value="2" />

4:复制一份comment.php命名为commen1.php,但是记得处理cmt_type=2

5:includes/lib_insert.php增加以下函数

function insert_comments1($arr)

{

$need_cache = $GLOBALS['smarty']->caching;

$need_compile = $GLOBALS['smarty']->force_compile;

$GLOBALS['smarty']->caching = false;

$GLOBALS['smarty']->force_compile = true;

/* 验证码相关设置 */

if ((intval($GLOBALS['_CFG']['captcha']) & CAPTCHA_COMMENT) && gd_version() > 0)

{

$GLOBALS['smarty']->assign('enabled_captcha', 1);

$GLOBALS['smarty']->assign('rand', mt_rand());

}

$GLOBALS['smarty']->assign('username', stripslashes($_SESSION['user_name']));

$GLOBALS['smarty']->assign('email', $_SESSION['email']);

$GLOBALS['smarty']->assign('comment_type', 2);

$GLOBALS['smarty']->assign('id', $arr['id']);

$cmt = assign_comment1($arr['id'], $arr['type']);

$GLOBALS['smarty']->assign('comments', $cmt['comments']);

$GLOBALS['smarty']->assign('pager', $cmt['pager']);

$val = $GLOBALS['smarty']->fetch('library/comments_list1.lbi');

$GLOBALS['smarty']->caching = $need_cache;

$GLOBALS['smarty']->force_compile = $need_compile;

return $val;

}

6:js/common.js增加咨询分页js

function gotoPage1(page, id, type)

{

Ajax.call('comment1.php?act=gotopage', 'page=' + page + '&id=' + id + '&type=2', gotoPageResp**e1, 'GET', 'JSON'); 这里也有问题gotoPageResponse1

}

function gotoPageResp**e1(result) 这里也是这个问题:gotoPageResponse1

{

document.getElementById("ECS_COMMENT1").innerHTML = result.content;

}

7:处理购买咨询函数

function assign_comment1($id, $type, $page = 1)

{

/* 取得评论列表 */

$count = $GLOBALS['db']->getOne('SELECT COUNT(*) FROM ' .$GLOBALS['ecs']->table('comment').

" WHERE id_value = '$id' AND comment_type = '2' AND status = 1 AND parent_id = 0");

$size = !empty($GLOBALS['_CFG']['comments_number']) ? $GLOBALS['_CFG']['comments_number'] : 5;

$page_count = ($count > 0) ? intval(ceil($count / $size)) : 1;

$sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('comment') .

" WHERE id_value = '$id' AND comment_type = '2' AND status = 1 AND parent_id = 0".

' ORDER BY comment_id DESC';

$res = $GLOBALS['db']->selectLimit($sql, $size, ($page-1) * $size);

$arr = array();

$ids = '';

while ($row = $GLOBALS['db']->fetchRow($res))

{

$ids .= $ids ? ",$row[comment_id]" : $row['comment_id'];

$arr[$row['comment_id']]['id'] = $row['comment_id'];

$arr[$row['comment_id']]['email'] = $row['email'];

$arr[$row['comment_id']]['username'] = $row['user_name'];

$arr[$row['comment_id']]['content'] = str_replace('/r/n', '<br />', htmlspecialchars($row['content']));

$arr[$row['comment_id']]['content'] = nl2br(str_replace('/n', '<br />', $arr[$row['comment_id']]['content']));

$arr[$row['comment_id']]['rank'] = $row['comment_rank'];

$arr[$row['comment_id']]['add_time'] = local_date($GLOBALS['_CFG']['time_format'], $row['add_time']);

}

/* 取得已有回复的评论 */

if ($ids)

{

$sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('comment') .

" WHERE parent_id IN( $ids )";

$res = $GLOBALS['db']->query($sql);

while ($row = $GLOBALS['db']->fetch_array($res))

{

$arr[$row['parent_id']]['re_content'] = nl2br(str_replace('/n', '<br />', htmlspecialchars($row['content'])));

$arr[$row['parent_id']]['re_add_time'] = local_date($GLOBALS['_CFG']['time_format'], $row['add_time']);

$arr[$row['parent_id']]['re_email'] = $row['email'];

$arr[$row['parent_id']]['re_username'] = $row['user_name'];

}

}

/* 分页样式 */

//$pager['styleid'] = isset($GLOBALS['_CFG']['page_style'])? intval($GLOBALS['_CFG']['page_style']) : 0;

$pager['page'] = $page;

$pager['size'] = $size;

$pager['record_count'] = $count;

$pager['page_count'] = $page_count;

$pager['page_first'] = "javascript:gotoPage(1,$id,$type)";

$pager['page_prev'] = $page > 1 ? "javascript:gotoPage(" .($page-1). ",$id,$type)" : 'javascript:;';

$pager['page_next'] = $page < $page_count ? 'javascript:gotoPage(' .($page + 1) . ",$id,$type)" : 'javascript:;';

$pager['page_last'] = $page < $page_count ? 'javascript:gotoPage(' .$page_count. ",$id,$type)" : 'javascript:;';

$cmt = array('comments' => $arr, 'pager' => $pager);

return $cmt;

}

8:后台根据cmt_type进行处理就OK了。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表