Ecshop模板网
首页 > ecshop教程 > ecshop经验分享 > 让ecshop商品评论和咨询显示分开的方法
文章详情

让ecshop商品评论和咨询显示分开的方法

ecshop模板网 / 2014-04-15

ecshop当中的咨询与评论是合到一起的,我们如果要让他分开显示,让网站显示的更加人性化,有没特别合适的方法 ,以下由ecshop模板堂提供的方法:

1:在ecshop的模板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="sel ectPageForm" 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 sel ectPage(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:处理ecshop商城购买咨询函数

 

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']->sel ectLimit($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:ecshop商城后台根据cmt_type进行处理就OK了。

下一篇: 如何调整ecshop所有会员的红包数量 上一篇: 将Ecshop后台fckeditor升级更改为kindeditor 4.1.10编辑器
 用户评论(共 1 条评论)
  • 匿名用户:分页没有改 $pager['page_prev'] = $page > 1 ? "javascript:gotoPage(" .($page-1). ",$id,$type)" : 'javascript:;'; 会有问题 ( 2014-08-28 16:38:44 )
用户名: 匿名用户 E-mail:
当前心情:
评论内容:
验证码: captcha
返回顶部 返回首页
 
QQ在线咨询
售前电话热线
#
售前QQ客服