[*] MO : Review of the productcomments module - Part1

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@7918 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
gBrunier
2011-08-05 15:09:46 +00:00
parent 13da28a2a8
commit 4d2740eb35
6 changed files with 326 additions and 118 deletions
+9 -10
View File
@@ -2,6 +2,15 @@
global $_MODULE;
$_MODULE = array();
$_MODULE['<{productcomments}prestashop>productcomments-extra_7c3b0e9898b88deee7ea75aafd2e37e2'] = 'Note moyenne';
$_MODULE['<{productcomments}prestashop>productcomments-extra_a71a0229e164fecdcde3c4e0f40473fa'] = 'Lire les avis utilisateurs';
$_MODULE['<{productcomments}prestashop>productcomments-extra_4ce7fa08d440a1e0fb369b1273e52ac3'] = 'Donner votre avis';
$_MODULE['<{productcomments}prestashop>productcomments-extra_b78a3223503896721cca1303f776159b'] = 'Titre';
$_MODULE['<{productcomments}prestashop>productcomments-extra_0be8406951cdfda82f00f79328cf4efc'] = 'Commentaire';
$_MODULE['<{productcomments}prestashop>productcomments-extra_a2ed44743411cf8b80e397448fce104c'] = 'Votre nom';
$_MODULE['<{productcomments}prestashop>productcomments-extra_94966d90747b97d1f0f206c98a8b1ac3'] = 'Envoyer';
$_MODULE['<{productcomments}prestashop>productcomments-extra_e81c4e4f2b7b93b481e13a8553c2ae1b'] = 'ou';
$_MODULE['<{productcomments}prestashop>productcomments-extra_ea4788705e6873b424c65e91c2846b19'] = 'Annuler';
$_MODULE['<{productcomments}prestashop>productcomments_b91c4e8b229a399a3bc911d352524a9b'] = 'Commentaires produits';
$_MODULE['<{productcomments}prestashop>productcomments_0c21532dfd3476791e5aab1aa7fa7405'] = 'Autorise les utilisateurs à poster des commentaires sur les produits';
$_MODULE['<{productcomments}prestashop>productcomments_f4d1ea475eaa85102e2b4e6d95da84bd'] = 'Confirmation';
@@ -56,17 +65,7 @@ $_MODULE['<{productcomments}prestashop>productcomments_6bf852d9850445291f5e9d474
$_MODULE['<{productcomments}prestashop>productcomments_6d28f2900adb9e500868166f6d04da92'] = 'Vous devez attendre';
$_MODULE['<{productcomments}prestashop>productcomments_ba8d7ae5dcadfba739f28a777378f208'] = 'secondes avant de poster un nouveau commentaire.';
$_MODULE['<{productcomments}prestashop>productcomments_7c3b0e9898b88deee7ea75aafd2e37e2'] = 'Note moyenne';
$_MODULE['<{productcomments}prestashop>productcomments_b1897515d548a960afe49ecf66a29021'] = 'Moyenne';
$_MODULE['<{productcomments}prestashop>productcomments_5da618e8e4b89c66fe86e32cdafde142'] = 'De';
$_MODULE['<{productcomments}prestashop>productcomments_b78a3223503896721cca1303f776159b'] = 'Titre';
$_MODULE['<{productcomments}prestashop>productcomments_08621d00a3a801b9159a11b8bbd69f89'] = 'Aucun commentaire n\'a été publié pour le moment.';
$_MODULE['<{productcomments}prestashop>productcomments_30b3dbf8b5c381c2e8d62189048ab37c'] = 'seconde(s) avant de poster un nouveau commentaire.';
$_MODULE['<{productcomments}prestashop>productcomments_c3edcf2cedbd4ce230fd6d4ea8915718'] = 'Ajouter un commentaire';
$_MODULE['<{productcomments}prestashop>productcomments_a2ed44743411cf8b80e397448fce104c'] = 'Votre nom :';
$_MODULE['<{productcomments}prestashop>productcomments_51ec9bf4aaeab1b25bb57f9f8d4de557'] = 'Titre : ';
$_MODULE['<{productcomments}prestashop>productcomments_240f3031f25601fa128bd4e15f0a37de'] = 'Commentaire :';
$_MODULE['<{productcomments}prestashop>productcomments_94966d90747b97d1f0f206c98a8b1ac3'] = 'Envoyer';
$_MODULE['<{productcomments}prestashop>productcomments_720fae7db6e6055d2b47890240bb3598'] = 'Seuls les utilisateurs enregistrés peuvent poster des commentaires.';
$_MODULE['<{productcomments}prestashop>products-comparison_8413c683b4b27cc3f4dbd4c90329d8ba'] = 'Commentaires';
$_MODULE['<{productcomments}prestashop>products-comparison_b1897515d548a960afe49ecf66a29021'] = 'Moyenne';
$_MODULE['<{productcomments}prestashop>products-comparison_bc976f6c3405523cde61f63a7cbe224b'] = 'Voir les avis';
@@ -0,0 +1,130 @@
{*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<script type="text/javascript" src="{$module_dir}js/jquery.rating.pack.js"></script>
<script type="text/javascript">
$(function(){literal}{{/literal} $('input[@type=radio].star').rating(); {literal}}{/literal});
$(function(){literal}{{/literal}
$('.auto-submit-star').rating({literal}{{/literal}
callback: function(value, link){literal}{{/literal}
{literal}}{/literal}
{literal}}{/literal});
{literal}}{/literal});
//close comment form
function closeCommentForm(){ldelim}
$('#sendComment').slideUp('fast');
$('input#addCommentButton').fadeIn('slow');
{rdelim}
$('document').ready(function(){literal}{{/literal}
$('#new_comment_btn').fancybox({literal}{{/literal}
'hideOnContentClick': false,
'onClosed': function(){literal}{{/literal}
{literal}}{/literal},
{literal}}{/literal});
$('a[href=#idTab5]').click(function(){literal}{{/literal}
$('*[id^="idTab"]').addClass('block_hidden_only_for_screen');
$('div#idTab5').removeClass('block_hidden_only_for_screen');
$('ul#more_info_tabs a[href^="#idTab"]').removeClass('selected');
$('a[href="#idTab5"]').addClass('selected');
{literal}}{/literal});
{literal}}{/literal});
</script>
<div id="product_comments_block_extra">
<div>
<span style="float:left;">{l s='Average grade' mod='productcomments'}&nbsp</span>
{section name="i" start=0 loop=5 step=1}
{if $averageTotal le $smarty.section.i.index}
<div class="star"></div>
{else}
<div class="star star_on"></div>
{/if}
{/section}
<br style="clear:both"/>
</div>
<div>
<a href="#idTab5">{l s='Read user reviews' mod='productcomments'} ({$nbComments})</a><br/>
{if ($too_early == false AND ($cookie->isLogged() == true OR $allow_guests == true))}
{if $cookie->isLogged() == true || $allow_guests == true}
<a id="new_comment_btn" href="#new_comment_form">{l s='Give your advice' mod='productcomments'}</a>
{/if}
{/if}
</div>
<div style="display: none;">
<div id="new_comment_form">
<div>
<form action="{$action_url}" method="post" id="sendComment">
<span class="title">{l s='Give your advice' mod='productcomments'}</span>
<div style="margin-top:20px">
<img style="float:left" src="{$link->getImageLink($product->link_rewrite, $productcomment_cover, 'medium')}" height="{$mediumSize.height}" width="{$mediumSize.width}" alt="{$product->name|escape:html:'UTF-8'}" />
<div style="float:left; width:300px; margin-left:10px">
<strong class="clearfix">{$product->name}</strong>
{$product->description_short}
</div>
</div>
<br style="clear:both"/>
<div style="margin-top:20px">
{if $criterions|@count > 0}
<table border="0" cellspacing="0" cellpadding="0">
{section loop=$criterions name=i start=0 step=1}
<tr>
<th>
<input type="hidden" name="id_product_comment_criterion_{$smarty.section.i.iteration}" value="{$criterions[i].id_product_comment_criterion|intval}" />
{$criterions[i].name|escape:'html':'UTF-8'}:&nbsp;
</th>
<td>
<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" id="{$smarty.section.i.iteration}_grade" value="1" />
<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" value="2" />
<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" value="3" checked="checked" />
<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" value="4" />
<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" value="5" />
</td>
</tr>
{/section}
</table>
{/if}
<label for="comment_title">{l s='Title' mod='productcomments'} *:</label>
<input name="title" type="text" value=""/><br/>
<label for="content">{l s='Comment' mod='productcomments'} *:</label>
<textarea name="content"></textarea>
{if $allow_guests == true && $cookie->isLogged() == false}
<label>{l s='Your name:' mod='productcomments'} *:</label>
<input name="customer_name" type="text" value=""/><br/>
{/if}
<p style="float:right">
<button name="submitMessage" type="submit">{l s='Send' mod='productcomments'}</button>&nbsp;
{l s='or' mod='productcomments'}&nbsp;<a href="#" onclick="$.fancybox.close();">{l s='Cancel' mod='productcomments'}</a>
</p>
<br style="clear:both"/>
</div>
</form>
</div>
</div>
</div>
</div>
+124
View File
@@ -0,0 +1,124 @@
#product_comments_block_extra {
border: 1px solid #D0D3D8;
background: #F1F2F4;
padding: 10px
}
#product_comments_block_extra a {
text-decoration: none;
font-weight: bold
}
#product_comments_block_extra a:hover {
text-decoration: underline
}
#product_comments_block_extra div.star {
background: url("img/star.gif") no-repeat scroll 0 0 transparent
}
#product_comments_block_extra div.star_on {
background: url("img/star.gif") no-repeat scroll 0 0 transparent;
background-position: 0 -16px
}
#new_comment_form {
color: #333;
background-color: #fff;
padding: 10px;
width: 565px;
text-align: left;
}
#new_comment_form .title {
padding: 15px;
background: #333;
color: #fff;
font-size: 13px;
font-weight: bold;
padding: 5px;
text-align: left;
text-transform: uppercase;
display: block;
margin: 5px 0
}
#new_comment_form label {
display: block;
margin: 5px 0;
text-align: left;
font-weight: bold
}
#new_comment_form textarea {
width: 100%;
min-height: 100px;
margin: 5px 0
}
#new_comment_form input[type=text] {
width: 100%;
height: 30px;
margin: 5px 0
}
#new_comment_form th {
font-size: 11px;
text-align: left;
font-weight: bold;
color: #333
}
#new_comment_form button {
background-color: #333;
border: solid 1px #BDC2C9;
padding: 3px 5px;
cursor: pointer;
color: #fff
}
#product_comments_block_tab div.comment {
border-bottom: solid 1px #ccc;
padding: 5px
}
#product_comments_block_tab div.comment div.comment_author {
float: left;
width: 200px
}
#product_comments_block_tab div.comment div.comment_details {
float: left;
width: 320px
}
#product_comments_block_tab div.comment_details p{
padding: 0
}
#product_comments_block_tab a {
text-decoration: none;
font-weight: bold
}
#product_comments_block_tab a:hover {
text-decoration: underline
}
#product_comments_block_tab div.star {
background: url("img/star.gif") no-repeat scroll 0 0 transparent
}
#product_comments_block_tab div.star_on {
background: url("img/star.gif") no-repeat scroll 0 0 transparent;
background-position: 0 -16px
}
#product_comments_block_tab button {
background-color: #bbb;
border: solid 1px #999;
padding: 1px;
cursor: pointer;
color: #fff;
border-radius: 3px
}
+34 -1
View File
@@ -66,7 +66,7 @@ class ProductComments extends Module
return false;
if (parent::install() == false OR $this->registerHook('productTab') == false
OR $this->registerHook('extraProductComparison') == false OR $this->registerHook('productTabContent') == false
OR $this->registerHook('header') == false OR !Configuration::updateValue('PRODUCT_COMMENTS_MINIMAL_TIME', 30)
OR $this->registerHook('header') == false OR $this->registerHook('extraRight') == false OR !Configuration::updateValue('PRODUCT_COMMENTS_MINIMAL_TIME', 30)
OR !Configuration::updateValue('PRODUCT_COMMENTS_ALLOW_GUESTS', 0)
OR !Configuration::updateValue('PRODUCT_COMMENTS_MODERATE', 1))
return false;
@@ -494,6 +494,38 @@ class ProductComments extends Module
return ($this->display(__FILE__, '/tab.tpl'));
}
public function hookExtraRight($params)
{
require_once(dirname(__FILE__).'/ProductComment.php');
require_once(dirname(__FILE__).'/ProductCommentCriterion.php');
$id_guest = (!$id_customer = (int)Context::getContext()->cookie->id_customer) ? (int)Context::getContext()->cookie->id_guest : false;
$customerComment = ProductComment::getByCustomer((int)(Tools::getValue('id_product')), (int)Context::getContext()->cookie->id_customer, true, (int)$id_guest);
$averages = ProductComment::getAveragesByProduct((int)Tools::getValue('id_product'), Context::getContext()->language->id);
$averageTotal = 0;
foreach ($averages AS $average)
$averageTotal += (float)($average);
$averageTotal = count($averages) ? ($averageTotal / count($averages)) : 0;
$image = Product::getCover((int)($_GET['id_product']));
Context::getContext()->smarty->assign(array(
'logged' => (int)Context::getContext()->cookie->id_customer,
'allow_guests' => (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'),
'productcomment_cover' => (int)Tools::getValue('id_product').'-'.(int)$image['id_image'],
'mediumSize' => Image::getSize('medium'),
'criterions' => ProductCommentCriterion::getByProduct((int)Tools::getValue('id_product'), Context::getContext()->language->id),
'action_url' => '',
'averageTotal' => (int)$averageTotal,
'too_early' => ($customerComment AND (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()),
'nbComments' => (int)(ProductComment::getCommentNumber((int)($_GET['id_product'])))
));
return ($this->display(__FILE__, '/productcomments-extra.tpl'));
}
private function _frontOfficePostProcess()
{
@@ -583,6 +615,7 @@ class ProductComments extends Module
public function hookHeader()
{
$this->context->controller->addCSS($this->_path.'productcomments.css', 'all');
$this->_frontOfficePostProcess();
}
+28 -106
View File
@@ -25,113 +25,35 @@
*}
<div id="idTab5">
<script type="text/javascript" src="{$module_dir}js/jquery.rating.pack.js"></script>
<script type="text/javascript">
$(function(){literal}{{/literal} $('input[@type=radio].star').rating(); {literal}}{/literal});
$(function(){literal}{{/literal}
$('.auto-submit-star').rating({literal}{{/literal}
callback: function(value, link){literal}{{/literal}
{literal}}{/literal}
{literal}}{/literal});
{literal}}{/literal});
//close comment form
function closeCommentForm(){ldelim}
$('#sendComment').slideUp('fast');
$('input#addCommentButton').fadeIn('slow');
{rdelim}
</script>
{if $comments}
{if $criterions|@count > 0}
<h2>{l s='Average grade' mod='productcomments'}</h2>
<div style="float: left">
{l s='Average' mod='productcomments'}:<br />
{section loop=6 step=1 start=1 name=average}
<input class="auto-submit-star" disabled="disabled" type="radio" name="average" {if $averageTotal|round neq 0 and $smarty.section.average.index eq $averageTotal|round}checked="checked"{/if} />
{/section}
</div>
<div style="float: left; margin-left: 40px; width: 400px">
{foreach from=$criterions item=c}
<div style="float: left; margin-left: 20px; margin-bottom: 10px;">
{$c.name|escape:'html':'UTF-8'}<br />
{section loop=6 step=1 start=1 name=average}
<input class="auto-submit-star" disabled="disabled" type="radio" name="{$c.name|escape:'html':'UTF-8'}_{$smarty.section.average.index}" value="{$smarty.section.average.index}" {if isset($averages[$c.id_product_comment_criterion]) AND $averages[$c.id_product_comment_criterion]|round neq 0 AND $smarty.section.average.index eq $averages[$c.id_product_comment_criterion]|round}checked="checked"{/if} />
{/section}
<div id="product_comments_block_tab">
{if $comments}
{foreach from=$comments item=comment}
{if $comment.content}
<div class="comment clearfix">
<div class="comment_author">
<span style="float:left;">{l s='Average grade' mod='productcomments'}&nbsp</span>
{section name="i" start=0 loop=5 step=1}
{if $comment.grade le $smarty.section.i.index}
<div class="star"></div>
{else}
<div class="star star_on"></div>
{/if}
{/section}
<br style="clear:both"/>
<div>
<strong>{$comment.customer_name|escape:'html':'UTF-8'}</strong><br/>
<em>{dateFormat date=$comment.date_add|escape:'html':'UTF-8' full=0}</em>
</div>
</div>
<div class="comment_details">
<h4>{$comment.title}</h4>
<p>{$comment.content|escape:'html':'UTF-8'|nl2br}</p>
</div>
</div>
{/if}
{/foreach}
</div>
{/if}
<div class="clear table_block">
<table class="std" style="width: 100%">
<thead>
<tr>
<th class="first_item" style="width:80px;">{l s='From' mod='productcomments'}</th>
<th class="item">{l s='Title' mod='productcomments'}</th>
<th class="item">{l s='Comment' mod='productcomments'}</th>
</tr>
</thead>
<tbody>
{foreach from=$comments item=comment}
{if $comment.content}
<tr>
<td style="vertical-align:top">
{dateFormat date=$comment.date_add|escape:'html':'UTF-8' full=0}
{$comment.customer_name|escape:'html':'UTF-8'}.
</td>
<td style="vertical-align:top">
{$comment.title}
</td>
<td style="vertical-align: top">
{$comment.content|escape:'html':'UTF-8'|nl2br}
</td>
</tr>
{/if}
{/foreach}
</tbody>
</table>
{else}
<p class="align_center">{l s='No customer comments for the moment.' mod='productcomments'}</p>
{/if}
</div>
{else}
<p class="align_center">{l s='No customer comments for the moment.' mod='productcomments'}</p>
{/if}
{if $too_early == true}
<p class="align_center">{l s='You should wait' mod='productcomments'} {$delay} {l s='second(s) before posting a new comment' mod='productcomments'}</p>
{elseif $cookie->isLogged() == true || $allow_guests == true}
<p class="align_center"><input style="margin:auto;" class="button_large" type="button" id="addCommentButton" value="{l s='Add a comment' mod='productcomments'}" onclick="$('#sendComment').slideDown('slow');$(this).slideUp('slow');" /></p>
<form action="{$action_url}" method="post" class="std" id="sendComment" style="display:none;">
<fieldset>
<p class="align_right"><a href="javascript:closeCommentForm()">X</a></p>
<p class="bold">{l s='Add a comment' mod='productcomments'}</p>
{if $criterions|@count > 0}
<table border="0" cellspacing="0" cellpadding="0">
{section loop=$criterions name=i start=0 step=1}
<tr>
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>
<input type="hidden" name="id_product_comment_criterion_{$smarty.section.i.iteration}" value="{$criterions[i].id_product_comment_criterion|intval}" />
{$criterions[i].name|escape:'html':'UTF-8'}
</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>
<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" id="{$smarty.section.i.iteration}_grade" value="1" />
<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" value="2" />
<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" value="3" checked="checked" />
<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" value="4" />
<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" value="5" />
</td>
</tr>
{/section}
</table>
{/if}
{if $allow_guests == true && $cookie->isLogged() == false}<p><label for="customer_name">{l s='Your name:' mod='productcomments'}</label><input type="text" name="customer_name" id="customer_name" /></p>{/if}
<p><label for="comment_title">{l s='Title:' mod='productcomments'}</label><input type="text" name="title" id="comment_title" /></p>
<p><label for="content">{l s='Comment:' mod='productcomments'}</label><textarea cols="46" rows="5" name="content" id="content"></textarea></p>
<p class="submit">
<input class="button" name="submitMessage" value="{l s='Send' mod='productcomments'}" type="submit" />
</p>
</fieldset>
</form>
{else}
<p class="align_center">{l s='Only registered users can post a new comment.' mod='productcomments'}</p>
{/if}
</div>
+1 -1
View File
@@ -24,4 +24,4 @@
* International Registered Trademark & Property of PrestaShop SA
*}
<li><a href="#idTab5" class="idTabHrefShort">{l s='Comments' mod='productcomments'} ({$nbComments})</a></li>
<li><a href="#idTab5" class="idTabHrefShort">{l s='Comments' mod='productcomments'}</a></li>