简单搞定ecshop商品评论和咨询分开
2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家
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 class="box"> <div class="box_1"> <div style="background:url(images/bg006.jpg) no-repeat; height:25px; line-height:25px; margin-top:15px; color:#FFFFFF; padding-left:40px;"> <span class="text">用户咨询</span> ({$lang.total} <font color="#FFFFFF">{$pager.record_count}</font> 用户咨询) </div> <div class="boxCenterList clearfix" style="height:1%;"> <ul class="comments"> <!-- {if $comments} --> <!-- {foreach from=$comments item=comment} --> <li class="word"> <font class="f2"><!-- {if $comment.username} -->{$comment.username|escape:html}<!-- {else} -->{$lang.anonymous}<!-- {/if} --></font> <font class="f3">( {$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 class="f1">{$lang.admin_username}</font>{$comment.re_content}</p> <!-- {/if} --> </li> <!-- {/foreach} --> <!--{else}--> <li>目前没有任何用户咨询</li> <!--{/if}--> </ul> <!--翻页 start--> <div id="pagebar" class="f_r"> <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" class="pagebar"> <span class="f_l f6" 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 class="prev" href="{$pager.page_prev}">{$lang.page_prev}</a><!-- {/if} --> <!--{foreach from=$pager.page_number key=key item=item}--> <!-- {if $pager.page eq $key} --> <span class="page_now">{$key}</span> <!-- {else} --> <a href="{$item}">[{$key}]</a> <!-- {/if} --> <!--{/foreach}--> <!-- {if $pager.page_next} --><a class="next" href="{$pager.page_next}">{$lang.page_next}</a><!-- {/if} --> <!-- {if $pager.page_last} --><a class="last" 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" class="B_blue" /></kbd> <!-- {/if} --> </div> <!--翻页 END--> <!-- {/if} --> </form> <script type="Text/Javascript" language="JavaScript"> <!-- {literal} function selectPage(sel) { sel.form.submit(); } {/literal} //--> </script> </div> <!--翻页 END--> <div class="blank5"></div> <!--评论表单 start--> <div class="commentsList"> <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}" class="inputBorder"/> </td> </tr> <tr> <td align="right" valign="top">{$lang.comment_content}:</td> <td> <textarea name="content" class="inputBorder" 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"class="inputBorder" style="width:50px; margin-left:5px;"/> <img src="captcha.php?{$rand}" alt="captcha" class="captcha"> </div> <!-- {/if} --> <input name="" type="submit"value=" " class="f_r" 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 class="blank5"></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) { 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'); } function gotoPageResp**e1(result) { 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了。 |
楼主太强了,太伟大了 |
不过,我是小白。第8步:后台根据cmt_type进行处理就OK了。看不懂,不会弄! 麻烦至尊写一下后台查看和回复吧! |
thank you |
很多人都会,但只有楼主分享出来了。 |
不错。支持一个了!这个不错! |
非管理员可否回复?给编辑权限了,可否也能回复呢? |
多谢!有用!! |
这让那些大侠情何以堪。。。 |
8:后台根据cmt_type进行处理就OK了,怎么处理,楼主好事做到底啊!!!呵呵 |
测试无法使用。 |
问题出在哪? 提示: lib_insert.php 这句$cmt = assign_comment1($arr['id'], $arr['type']); 出错 Fatal error: Call to undefined function assign_comment1() in D:\PHP\vhosts\baobao\includes\lib_insert.php on line 455 |
已经解决~~哈哈 |
留个脚印,下次备用。谢谢分享 |
最近更新
常用插件
- ecshop分类批量扩展插件
ecshop分类批量扩展插件,这个插件是ecshop插件里面比较核心的插件。我们...
- ecshop商品分类名称增加样
ecshop插件介绍:本插件可以方便在后台管理,为ecshop商品分类名称增加样...
- ecshop2.7.1打印发货单插件
ecshop2.7.1打印发货单插件介绍:ecshop2.7.1和以前的ecshop版本不一样,ecs...
- ecshop二次商品订购人信息
ecshop二次商品订购人信息填写插件,有时候给朋友送花,或者是送礼品的...
- ecshop二次开发详细页面生
插件介绍: ECSHOP系统,在很多时候,很多商品没有人购买,不但购买的人...
ecshop热门问答
ecshop热门资料
ecshop325718846
ecshop订单查询
ecshopxml
ecshopdat
ecshopcls_smtp
ecshop主机租用
ecshop交易
ecshop淘宝账号
ecshop淘宝描述采集
ecshop加入收藏夹
ecshopMSQ
phphproce
ecshop今日特价
ecshopTable
ecshop合作
ecshop163邮箱
ecshop商品详情
ecshop购物车清空
网店备案
ecshop免费开店
ecshop邮件无限发送
ecshop解求
ecshop订单跟踪
ecshop祖国
ecshopexceeds
ecshop物价
ecshop道理
ecshop三五互联
model实例
ecshop广告分析