diff --git a/modules/productcomments/ProductComment.php b/modules/productcomments/ProductComment.php index 7e9cb8774..12d2c7da4 100644 --- a/modules/productcomments/ProductComment.php +++ b/modules/productcomments/ProductComment.php @@ -41,7 +41,6 @@ class ProductComment extends ObjectModel /** @var integer Guest's id */ public $id_guest; - /** @var integer Customer name */ public $customer_name; @@ -118,22 +117,19 @@ class ProductComment extends ObjectModel * * @return arrayComments */ - public static function getByCustomer($id_product, $id_customer, $last = false, $id_guest = false) + public static function getByCustomer($id_product, $id_customer, $get_last = false, $id_guest = false) { $results = Db::getInstance()->executeS(' - SELECT * - FROM `'._DB_PREFIX_.'product_comment` pc - WHERE pc.`id_product` = '.(int)$id_product.' - AND '.(!$id_guest ? 'pc.`id_customer` = '.(int)$id_customer : 'pc.`id_guest` = '.(int)$id_guest).' - ORDER BY pc.`date_add` DESC ' - .($last ? 'LIMIT 1' : '') + SELECT * + FROM `'._DB_PREFIX_.'product_comment` pc + WHERE pc.`id_product` = '.(int)$id_product.' + AND '.(!$id_guest ? 'pc.`id_customer` = '.(int)$id_customer : 'pc.`id_guest` = '.(int)$id_guest).' + ORDER BY pc.`date_add` DESC ' + .($get_last ? 'LIMIT 1' : '') ); - if (!$results) - return false; - elseif ($last) - return array_shift($results); - else + if ($get_last) + $results = array_shift($results); return $results; } diff --git a/modules/productcomments/ProductCommentCriterion.php b/modules/productcomments/ProductCommentCriterion.php index bab2ed2e4..10275bf04 100644 --- a/modules/productcomments/ProductCommentCriterion.php +++ b/modules/productcomments/ProductCommentCriterion.php @@ -43,7 +43,6 @@ class ProductCommentCriterion extends ObjectModel 'fields' => array( 'id_product_comment_criterion_type' => array('type' => self::TYPE_INT), 'active' => array('type' => self::TYPE_BOOL), - // Lang fields 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128), ) @@ -54,16 +53,23 @@ class ProductCommentCriterion extends ObjectModel if (!parent::delete()) return false; if ($this->id_product_comment_criterion_type == 2) - if (!Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'product_comment_criterion_category - WHERE id_product_comment_criterion='.(int)$this->id)) + { + if (!Db::getInstance()->execute(' + DELETE FROM '._DB_PREFIX_.'product_comment_criterion_category + WHERE id_product_comment_criterion='.(int)$this->id)) return false; + } elseif ($this->id_product_comment_criterion_type == 3) - if (!Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'product_comment_criterion_product - WHERE id_product_comment_criterion='.(int)$this->id)) + { + if (!Db::getInstance()->execute(' + DELETE FROM '._DB_PREFIX_.'product_comment_criterion_product + WHERE id_product_comment_criterion='.(int)$this->id)) return false; + } - return Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_comment_grade` - WHERE `id_product_comment_criterion` = '.(int)$this->id); + return Db::getInstance()->execute(' + DELETE FROM `'._DB_PREFIX_.'product_comment_grade` + WHERE `id_product_comment_criterion` = '.(int)$this->id); } public function update($nullValues = false) @@ -74,11 +80,13 @@ class ProductCommentCriterion extends ObjectModel if ($previousUpdate->id_product_comment_criterion_type != $this->id_product_comment_criterion_type) { if ($previousUpdate->id_product_comment_criterion_type == 2) - return Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'product_comment_criterion_category - WHERE id_product_comment_criterion='.(int)$previousUpdate->id); + return Db::getInstance()->execute(' + DELETE FROM '._DB_PREFIX_.'product_comment_criterion_category + WHERE id_product_comment_criterion = '.(int)$previousUpdate->id); elseif ($previousUpdate->id_product_comment_criterion_type == 3) - return Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'product_comment_criterion_product - WHERE id_product_comment_criterion='.(int)$previousUpdate->id); + return Db::getInstance()->execute(' + DELETE FROM '._DB_PREFIX_.'product_comment_criterion_product + WHERE id_product_comment_criterion = '.(int)$previousUpdate->id); } return true; } @@ -92,8 +100,10 @@ class ProductCommentCriterion extends ObjectModel { if (!Validate::isUnsignedId($id_product)) die(Tools::displayError()); - return (Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'product_comment_criterion_product` (`id_product_comment_criterion`, `id_product`) - VALUES('.(int)$this->id.','.(int)$id_product.')')); + return Db::getInstance()->execute(' + INSERT INTO `'._DB_PREFIX_.'product_comment_criterion_product` (`id_product_comment_criterion`, `id_product`) + VALUES('.(int)$this->id.','.(int)$id_product.') + '); } /** @@ -105,8 +115,10 @@ class ProductCommentCriterion extends ObjectModel { if (!Validate::isUnsignedId($id_category)) die(Tools::displayError()); - return (Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'product_comment_criterion_category` (`id_product_comment_criterion`, `id_category`) - VALUES('.(int)$this->id.','.(int)$id_category.')')); + return Db::getInstance()->execute(' + INSERT INTO `'._DB_PREFIX_.'product_comment_criterion_category` (`id_product_comment_criterion`, `id_category`) + VALUES('.(int)$this->id.','.(int)$id_category.') + '); } /** @@ -120,7 +132,7 @@ class ProductCommentCriterion extends ObjectModel die(Tools::displayError()); if ($grade < 0) $grade = 0; - else if ($grade > 10) + elseif ($grade > 10) $grade = 10; return (Db::getInstance()->execute(' INSERT INTO `'._DB_PREFIX_.'product_comment_grade` @@ -149,14 +161,25 @@ class ProductCommentCriterion extends ObjectModel $alias = 'ps'; } return Db::getInstance()->executeS(' - SELECT pcc.`id_product_comment_criterion`, pccl.`name` - FROM `'._DB_PREFIX_.'product_comment_criterion` pcc - LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_lang` pccl ON (pcc.id_product_comment_criterion = pccl.id_product_comment_criterion) - LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_product` pccp ON (pcc.`id_product_comment_criterion` = pccp.`id_product_comment_criterion` AND pccp.`id_product` = '.(int)$id_product.') - LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_category` pccc ON (pcc.`id_product_comment_criterion` = pccc.`id_product_comment_criterion`) - LEFT JOIN `'._DB_PREFIX_.'product'.$table.'` '.$alias.' ON ('.$alias.'.id_category_default = pccc.id_category AND '.$alias.'.id_product = '.(int)$id_product.') - WHERE pccl.`id_lang` = '.(int)($id_lang).' AND (pccp.id_product IS NOT NULL OR ps.id_product IS NOT NULL OR pcc.id_product_comment_criterion_type = 1) AND pcc.active = 1 - GROUP BY pcc.id_product_comment_criterion'); + SELECT pcc.`id_product_comment_criterion`, pccl.`name` + FROM `'._DB_PREFIX_.'product_comment_criterion` pcc + LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_lang` pccl + ON (pcc.id_product_comment_criterion = pccl.id_product_comment_criterion) + LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_product` pccp + ON (pcc.`id_product_comment_criterion` = pccp.`id_product_comment_criterion` AND pccp.`id_product` = '.(int)$id_product.') + LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_category` pccc + ON (pcc.`id_product_comment_criterion` = pccc.`id_product_comment_criterion`) + LEFT JOIN `'._DB_PREFIX_.'product'.$table.'` '.$alias.' + ON ('.$alias.'.id_category_default = pccc.id_category AND '.$alias.'.id_product = '.(int)$id_product.') + WHERE pccl.`id_lang` = '.(int)($id_lang).' + AND ( + pccp.id_product IS NOT NULL + OR ps.id_product IS NOT NULL + OR pcc.id_product_comment_criterion_type = 1 + ) + AND pcc.active = 1 + GROUP BY pcc.id_product_comment_criterion + '); } /** @@ -168,20 +191,21 @@ class ProductCommentCriterion extends ObjectModel { if (!Validate::isUnsignedId($id_lang)) die(Tools::displayError()); - return (Db::getInstance()->executeS(' - SELECT pcc.`id_product_comment_criterion`, pcc.id_product_comment_criterion_type, pccl.`name`, pcc.active - FROM `'._DB_PREFIX_.'product_comment_criterion` pcc - JOIN `'._DB_PREFIX_.'product_comment_criterion_lang` pccl ON (pcc.id_product_comment_criterion = pccl.id_product_comment_criterion) - WHERE pccl.`id_lang` = '.(int)$id_lang.($active ? ' AND active = 1' : '').($type ? ' AND id_product_comment_criterion_type = '.(int)$type : '').' - ORDER BY pccl.`name` ASC')); + return Db::getInstance()->executeS(' + SELECT pcc.`id_product_comment_criterion`, pcc.id_product_comment_criterion_type, pccl.`name`, pcc.active + FROM `'._DB_PREFIX_.'product_comment_criterion` pcc + JOIN `'._DB_PREFIX_.'product_comment_criterion_lang` pccl ON (pcc.id_product_comment_criterion = pccl.id_product_comment_criterion) + WHERE pccl.`id_lang` = '.(int)$id_lang.($active ? ' AND active = 1' : '').($type ? ' AND id_product_comment_criterion_type = '.(int)$type : '').' + ORDER BY pccl.`name` ASC + '); } public function getProducts() { $res = Db::getInstance()->executeS(' - SELECT pccp.id_product, pccp.id_product_comment_criterion - FROM `'._DB_PREFIX_.'product_comment_criterion_product` pccp - WHERE pccp.id_product_comment_criterion = '.(int)$this->id); + SELECT pccp.id_product, pccp.id_product_comment_criterion + FROM `'._DB_PREFIX_.'product_comment_criterion_product` pccp + WHERE pccp.id_product_comment_criterion = '.(int)$this->id); $products = array(); if ($res) foreach ($res AS $row) @@ -192,9 +216,9 @@ class ProductCommentCriterion extends ObjectModel public function getCategories() { $res = Db::getInstance()->executeS(' - SELECT pccc.id_category, pccc.id_product_comment_criterion - FROM `'._DB_PREFIX_.'product_comment_criterion_category` pccc - WHERE pccc.id_product_comment_criterion = '.(int)$this->id); + SELECT pccc.id_category, pccc.id_product_comment_criterion + FROM `'._DB_PREFIX_.'product_comment_criterion_category` pccc + WHERE pccc.id_product_comment_criterion = '.(int)$this->id); $criterions = array(); if ($res) foreach ($res AS $row) @@ -204,19 +228,27 @@ class ProductCommentCriterion extends ObjectModel public function deleteCategories() { - return Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_comment_criterion_category` WHERE `id_product_comment_criterion` = '.(int)$this->id); + return Db::getInstance()->execute(' + DELETE FROM `'._DB_PREFIX_.'product_comment_criterion_category` + WHERE `id_product_comment_criterion` = '.(int)$this->id); } public function deleteProducts() { - return Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_comment_criterion_product` WHERE `id_product_comment_criterion` = '.(int)$this->id); + return Db::getInstance()->execute(' + DELETE FROM `'._DB_PREFIX_.'product_comment_criterion_product` + WHERE `id_product_comment_criterion` = '.(int)$this->id); } public static function getTypes() { // Instance of module class for translations - $module = new MailAlerts(); + $module = new ProductComments(); - return array(1 => $module->l('Valid for the entire catalog', 'ProductCommentCriterion'), 2 => $module->l('Restricted to some categories', 'ProductCommentCriterion'), 3 => $module->l('Restricted to some products', 'ProductCommentCriterion')); + return array( + 1 => $module->l('Valid for the entire catalog', 'ProductCommentCriterion'), + 2 => $module->l('Restricted to some categories', 'ProductCommentCriterion'), + 3 => $module->l('Restricted to some products', 'ProductCommentCriterion') + ); } -} \ No newline at end of file +} diff --git a/modules/productcomments/controllers/front/default.php b/modules/productcomments/controllers/front/default.php new file mode 100644 index 000000000..a62a0eb26 --- /dev/null +++ b/modules/productcomments/controllers/front/default.php @@ -0,0 +1,171 @@ + +* @copyright 2007-2012 PrestaShop SA +* @version Release: $Revision: 15094 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +// Include Module +include_once(dirname(__FILE__).'/../../productcomments.php'); +// Include Models +include_once(dirname(__FILE__).'/../../ProductComment.php'); +include_once(dirname(__FILE__).'/../../ProductCommentCriterion.php'); + +class ProductCommentsDefaultModuleFrontController extends ModuleFrontController +{ + public function __construct() + { + parent::__construct(); + + $this->context = Context::getContext(); + } + + public function initContent() + { + parent::initContent(); + + if (Tools::isSubmit('action')) + { + switch(Tools::getValue('action')) + { + case 'add_comment': + $this->ajaxProcessAddComment(); + break; + case 'report_abuse': + $this->ajaxProcessReportAbuse(); + break; + case 'comment_is_usefull': + $this->ajaxProcessCommentIsUsefull(); + break; + } + } + } + + protected function ajaxProcessAddComment() + { + $module_instance = new ProductComments(); + + $result = true; + $id_guest = 0; + $id_customer = $this->context->customer->id; + if ($id_customer) + $id_guest = $this->context->cookie->id_guest; + + $errors = array(); + // Validation + if (!Validate::isInt(Tools::getValue('id_product'))) + $errors[] = $module_instance->l('ID product is incorrect'); + if (!Tools::getValue('title') || !Validate::isGenericName(Tools::getValue('title'))) + $errors[] = $module_instance->l('Title is incorrect'); + if (!Tools::getValue('content') || !Validate::isMessage(Tools::getValue('content'))) + $errors[] = $module_instance->l('Comment is incorrect'); + if (!$id_customer && (!Tools::isSubmit('customer_name') || !Tools::getValue('customer_name') || !Validate::isGenericName(Tools::getValue('customer_name')))) + $errors[] = $module_instance->l('Customer name is incorrect'); + if (!$this->context->customer->id && !Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS')) + $errors[] = $module_instance->l('You must be logged in order to send a comment'); + if (!count(Tools::getValue('criterion'))) + $errors[] = $module_instance->l('You must give a rating'); + + $product = new Product(Tools::getValue('id_product')); + if (!$product->id) + $errors[] = $module_instance->l('Product not found'); + + if (!count($errors)) + { + $customer_comment = ProductComment::getByCustomer(Tools::getValue('id_product'), $id_customer, true, $id_guest); + if (!$customer_comment || ($customer_comment && (strtotime($customer_comment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) < time())) + { + + $comment = new ProductComment(); + $comment->content = strip_tags(Tools::getValue('content')); + $comment->id_product = (int)Tools::getValue('id_product'); + $comment->id_customer = $id_customer; + $comment->id_guest = $id_guest; + $comment->customer_name = Tools::getValue('customer_name'); + if (!$comment->id_customer) + $comment->customer_name = pSQL($this->context->customer->firstname.' '.$this->context->customer->lastname); + $comment->title = Tools::getValue('title'); + $comment->grade = 0; + $comment->validate = 0; + $comment->save(); + + $grade_sum = 0; + foreach(Tools::getValue('criterion') as $id_product_comment_criterion => $grade) + { + $grade_sum += $grade; + $product_comment_criterion = new ProductCommentCriterion($id_product_comment_criterion); + if ($product_comment_criterion->id) + $product_comment_criterion->addGrade($comment->id, $grade); + } + + if (count(Tools::getValue('criterion')) > 1) + { + $comment->grade = $grade_sum / count(Tools::getValue('criterion')); + // Update Grade average of comment + $comment->save(); + } + $result = true; + } + else + { + $result = false; + $errors[] = $module_instance->l('You should wait').' '.Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME').' '.$module_instance->l('seconds before posting a new comment'); + } + } + else + $result = false; + + die(Tools::jsonEncode(array( + 'result' => $result, + 'errors' => $errors + ))); + } + + protected function ajaxProcessReportAbuse() + { + if (!Tools::isSubmit('id_product_comment')) + die('0'); + + if (ProductComment::isAlreadyReport(Tools::getValue('id_product_comment'), $this->context->cookie->id_customer)) + die('0'); + + if (ProductComment::reportComment((int)Tools::getValue('id_product_comment'), $this->context->cookie->id_customer)) + die('1'); + + die('0'); + } + + protected function ajaxProcessCommentIsUsefull() + { + if (!Tools::isSubmit('id_product_comment') || !Tools::isSubmit('value')) + die('0'); + + if (ProductComment::isAlreadyUsefulness(Tools::getValue('id_product_comment'), $this->context->cookie->id_customer)) + die('0'); + + if (ProductComment::setCommentUsefulness((int)Tools::getValue('id_product_comment'), (bool)Tools::getValue('value'), $this->context->cookie->id_customer)) + die('1'); + + die('0'); + } +} diff --git a/modules/productcomments/js/productcomments.js b/modules/productcomments/js/productcomments.js new file mode 100644 index 000000000..50799839f --- /dev/null +++ b/modules/productcomments/js/productcomments.js @@ -0,0 +1,80 @@ +$(function() { + $('input[@type=radio].star').rating(); + $('.auto-submit-star').rating(); + + $('.open-comment-form').fancybox({ + 'hideOnContentClick': false + }); + + $('button.usefulness_btn').click(function() { + var id_product_comment = $(this).data('id-product-comment'); + var is_usefull = $(this).data('is-usefull'); + var parent = $(this).parent(); + + $.ajax({ + url: productcomments_controller_url, + data: { + id_product_comment: id_product_comment, + action: 'comment_is_usefull', + value: is_usefull + }, + type: 'POST', + success: function(result){ + parent.fadeOut('slow', function() { + parent.remove(); + }); + } + }); + }); + + $('span.report_btn').click(function() { + if (confirm(confirm_report_message)) + { + var idProductComment = $(this).data('id-product-comment'); + var parent = $(this).parent(); + + $.ajax({ + url: productcomments_controller_url, + data: { + id_product_comment: idProductComment, + action: 'report_abuse' + }, + type: 'POST', + success: function(result){ + parent.fadeOut('slow', function() { + parent.remove(); + }); + } + }); + } + }); + + $('#submitNewMessage').click(function(e) { + // Kill default behaviour + e.preventDefault(); + + // Form element + $.ajax({ + url: productcomments_controller_url+'&action=add_comment&secure_key='+secure_key, + data: $('#fancybox-content form').serialize(), + type: 'POST', + dataType: "json", + success: function(data){ + if (data.result) + { + $.fancybox.close(); + document.location.href = document.location.href; + } + else + { + $('#new_comment_form_error ul').html(''); + $.each(data.errors, function(index, value) { + $('#new_comment_form_error ul').append('
  • '+value+'
  • '); + }); + $('#new_comment_form_error').slideDown('slow'); + } + } + }); + return false; + }); +}); diff --git a/modules/productcomments/productcomments-ajax.php b/modules/productcomments/productcomments-ajax.php index db648c310..d75dc2113 100644 --- a/modules/productcomments/productcomments-ajax.php +++ b/modules/productcomments/productcomments-ajax.php @@ -25,6 +25,7 @@ * International Registered Trademark & Property of PrestaShop SA */ +// The usage of this file is deprecated !!! require_once(dirname(__FILE__).'/../../config/config.inc.php'); require_once(dirname(__FILE__).'/../../init.php'); require_once(dirname(__FILE__).'/ProductCommentCriterion.php'); diff --git a/modules/productcomments/productcomments-extra.tpl b/modules/productcomments/productcomments-extra.tpl index 78c5a68be..bd9506eff 100644 --- a/modules/productcomments/productcomments-extra.tpl +++ b/modules/productcomments/productcomments-extra.tpl @@ -23,105 +23,17 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} -{literal} -{/literal}
    {if $nbComments != 0} @@ -144,65 +56,8 @@ {l s='Read user reviews' mod='productcomments'} ({$nbComments})
    {/if} {if ($too_early == false AND ($logged OR $allow_guests))} - {l s='Write your review' mod='productcomments'} + {l s='Write your review' mod='productcomments'} {/if}
    -
    -
    -

    {l s='Write your review' mod='productcomments'}

    -
    - {$product->name|escape:html:'UTF-8'} -
    -

    {$product->name}

    - {$product->description_short} -
    -
    - -
    -

    {l s='Write your review' mod='productcomments'}

    - {if $criterions|@count > 0} -
      - {section loop=$criterions name=i start=0 step=1} -
    • - - - {$criterions[i].name|escape:'html':'UTF-8'}:  - -
      - - - - - -
      -
    • - {/section} -
    - {/if} -
    -

    - - -

    -

    - - -

    - {if $allow_guests == true && $logged == 0} -

    - - -

    - {/if} -

    - - {l s='Cancel' mod='productcomments'}  - {l s='or' mod='productcomments'}   -

    -

    * {l s='Required fields' mod='productcomments'}

    -
    -
    -
    -
    - \ No newline at end of file + diff --git a/modules/productcomments/productcomments.css b/modules/productcomments/productcomments.css index cd150335e..7b3551c81 100644 --- a/modules/productcomments/productcomments.css +++ b/modules/productcomments/productcomments.css @@ -27,7 +27,7 @@ #product_comments_block_extra .comments_advices {clear:both;} /* pop-in add grade/advice ********************************************************************* */ -#fancybox-wrap {width:585px !important} +#fancybox-wrap { width:585px !important } #fancybox-content { width:585px !important; border-width:0 !important @@ -68,7 +68,6 @@ #new_comment_form .grade_content {margin:0 0 20px 0} #new_comment_form .grade_content span, -#new_comment_form .grade_content .star_content {float:left} #new_comment_form .grade_content span { display:inline-block; padding:0 10px; @@ -83,39 +82,29 @@ } .new_comment_form_content .intro_form { padding-bottom: 10px; - font-weight: bold; - font-size: 12px + font-weight: bold; + font-size: 12px } - -#new_comment_form .form_contenair { - clear:both; - margin-top:20px -} -#new_comment_form p.text -#new_comment_form p.textarea { - margin-bottom:0; - padding-bottom:0 -} -#new_comment_form p.text label, #new_comment_form p.textarea label { - display: block; +#new_comment_form label { + display: block; margin:12px 0 4px 0; - font-weight: bold; - font-size: 12px; + font-weight: bold; + font-size: 12px; } -#new_comment_form p.text input { - padding: 0 5px; - height: 28px; - width: 540px; - border: 1px solid #ccc; - background: #fff; -} -#new_comment_form p.textarea textarea { +#new_comment_form input { padding: 0 5px; - height: 80px; - width: 540px; - border: 1px solid #ccc; - background: #fff; + height: 28px; + width: 540px; + border: 1px solid #ccc; + background: #fff; +} +#new_comment_form textarea { + padding: 0 5px; + height: 80px; + width: 540px; + border: 1px solid #ccc; + background: #fff; } #new_comment_form .submit { @@ -126,20 +115,40 @@ } #new_comment_form button { cursor: pointer; - cursor: pointer; - display: inline-block; - padding: 4px 7px 3px 7px; - border: 1px solid #CC9900; - border-radius: 3px 3px 3px 3px; - font-weight: bold; - color: #000; + cursor: pointer; + display: inline-block; + padding: 4px 7px 3px 7px; + border: 1px solid #CC9900; + border-radius: 3px 3px 3px 3px; + font-weight: bold; + color: #000; background: url(img/bg_bt.gif) repeat-x scroll 0 0 #F4B61B } -#new_comment_form .submit .txt_required { - float:left; - font-size:12px; - font-style:italic; - color:#666 + +#new_comment_form #criterions_list { + border-bottom: 1px solid #CCC; + padding-bottom: 15px; + list-style-type: none; +} + +#new_comment_form #criterions_list li { + margin-bottom: 10px; +} + +#new_comment_form #criterions_list label { + display: inline; + float: left; + margin: 0 0 0 60px; +} + +#new_comment_form #criterions_list .star_content { + float: right; + margin-right: 180px; +} + +#new_comment_form #new_comment_form_footer { + margin-top: 20px; + font-size: 12px; } /* TAB COMMENTS ******************************************************************************** */ @@ -195,18 +204,21 @@ #product_comments_block_tab a:hover {text-decoration: underline} #product_comments_block_tab button.usefulness_btn { - cursor: pointer; + cursor: pointer; margin:0 0 0 5px; - display: inline-block; - padding: 0 2px; - border: 1px solid #CC9900; - border-radius: 3px 3px 3px 3px; - color: #000; - font-weight: bold; + display: inline-block; + padding: 0 2px; + border: 1px solid #CC9900; + border-radius: 3px 3px 3px 3px; + color: #000; + font-weight: bold; background: url("img/bg_bt.gif") repeat-x scroll 0 0 #F4B61B } #product_comments_block_tab button.usefulness_btn:hover {background-position: left -50px} #product_comments_block_tab button.usefulness_btn:active {background-position: left -100px} #product_comments_block_tab span.report_btn {cursor: pointer} -#product_comments_block_tab span.report_btn:hover {text-decoration:underline} \ No newline at end of file +#product_comments_block_tab span.report_btn:hover {text-decoration:underline} + +.fl { float: left; } +.fr { float: right; } diff --git a/modules/productcomments/productcomments.php b/modules/productcomments/productcomments.php index 36c5cd4c9..5cb1a8502 100644 --- a/modules/productcomments/productcomments.php +++ b/modules/productcomments/productcomments.php @@ -42,7 +42,7 @@ class ProductComments extends Module { $this->name = 'productcomments'; $this->tab = 'front_office_features'; - $this->version = '2.2'; + $this->version = '2.3'; $this->author = 'PrestaShop'; $this->need_instance = 0; $this->secure_key = Tools::encrypt($this->name); @@ -496,7 +496,7 @@ class ProductComments extends Module '; require_once(dirname(__FILE__).'/ProductCommentCriterion.php'); - $criterions = ProductCommentCriterion::getCriterions(Context::getContext()->language->id); + $criterions = ProductCommentCriterion::getCriterions($this->context->language->id); if (count($criterions)) { $this->_html .= '
    @@ -529,7 +529,7 @@ class ProductComments extends Module { include_once(dirname(__FILE__).'/ProductCommentCriterion.php'); - $criterions = ProductCommentCriterion::getCriterions(Context::getContext()->language->id, false, true); + $criterions = ProductCommentCriterion::getCriterions($this->context->language->id, false, true); $id_criterion = (int)Tools::getValue('updateCriterion'); if ($id_criterion) @@ -537,13 +537,13 @@ class ProductComments extends Module $criterion = new ProductCommentCriterion((int)$id_criterion); if ($criterion->id_product_comment_criterion_type == 2) { - $categories = Category::getSimpleCategories(Context::getContext()->language->id); + $categories = Category::getSimpleCategories($this->context->language->id); $criterion_categories = $criterion->getCategories(); } else if ($criterion->id_product_comment_criterion_type == 3) { $criterion_products = $criterion->getProducts(); - $products = Product::getSimpleProducts(Context::getContext()->language->id); + $products = Product::getSimpleProducts($this->context->language->id); } } @@ -682,11 +682,12 @@ class ProductComments extends Module require_once(dirname(__FILE__).'/ProductComment.php'); require_once(dirname(__FILE__).'/ProductCommentCriterion.php'); - Context::getContext()->smarty->assign(array( - 'allow_guests' => (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'), - 'comments' => ProductComment::getByProduct((int)(Tools::getValue('id_product'))), - 'criterions' => ProductCommentCriterion::getByProduct((int)(Tools::getValue('id_product')), Context::getContext()->language->id), - 'nbComments' => (int)(ProductComment::getCommentNumber((int)(Tools::getValue('id_product')))))); + $this->context->smarty->assign(array( + 'allow_guests' => (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'), + 'comments' => ProductComment::getByProduct((int)(Tools::getValue('id_product'))), + 'criterions' => ProductCommentCriterion::getByProduct((int)(Tools::getValue('id_product')), $this->context->language->id), + 'nbComments' => (int)(ProductComment::getCommentNumber((int)(Tools::getValue('id_product')))) + )); return ($this->display(__FILE__, '/tab.tpl')); } @@ -696,22 +697,22 @@ class ProductComments extends Module 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); + $id_guest = (!$id_customer = (int)$this->context->cookie->id_customer) ? (int)$this->context->cookie->id_guest : false; + $customerComment = ProductComment::getByCustomer((int)(Tools::getValue('id_product')), (int)$this->context->cookie->id_customer, true, (int)$id_guest); $average = ProductComment::getAverageGrade((int)Tools::getValue('id_product')); $image = Product::getCover((int)Tools::getValue('id_product')); - Context::getContext()->smarty->assign(array( + $this->context->smarty->assign(array( 'id_product_comment_form' => (int)Tools::getValue('id_product'), - 'product' => new Product((int)Tools::getValue('id_product'), false, Context::getContext()->language->id), + 'product' => new Product((int)Tools::getValue('id_product'), false, $this->context->language->id), 'secure_key' => $this->secure_key, - 'logged' => (int)Context::getContext()->customer->isLogged(true), + 'logged' => (int)$this->context->customer->isLogged(true), '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), + 'criterions' => ProductCommentCriterion::getByProduct((int)Tools::getValue('id_product'), $this->context->language->id), 'action_url' => '', 'averageTotal' => (int)$average['grade'], 'too_early' => ($customerComment && (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()), @@ -721,55 +722,50 @@ class ProductComments extends Module return ($this->display(__FILE__, '/productcomments-extra.tpl')); } - private function _frontOfficePostProcess() - { - - } - public function hookProductTabContent($params) { - $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); + $this->context->controller->addJS($this->_path.'js/jquery.rating.pack.js'); + $this->context->controller->addJS($this->_path.'js/jquery.textareaCounter.plugin.js'); + $this->context->controller->addJS($this->_path.'js/productcomments.js'); - $averages = ProductComment::getAveragesByProduct((int)Tools::getValue('id_product'), Context::getContext()->language->id); + $id_guest = (!$id_customer = (int)$this->context->cookie->id_customer) ? (int)$this->context->cookie->id_guest : false; + $customerComment = ProductComment::getByCustomer((int)(Tools::getValue('id_product')), (int)$this->context->cookie->id_customer, true, (int)$id_guest); + + $averages = ProductComment::getAveragesByProduct((int)Tools::getValue('id_product'), $this->context->language->id); $averageTotal = 0; foreach ($averages as $average) $averageTotal += (float)($average); $averageTotal = count($averages) ? ($averageTotal / count($averages)) : 0; - Context::getContext()->smarty->assign(array( - 'logged' => (int)Context::getContext()->customer->isLogged(true), - 'action_url' => '', - 'comments' => ProductComment::getByProduct((int)Tools::getValue('id_product'), 1, null, Context::getContext()->cookie->id_customer), - 'criterions' => ProductCommentCriterion::getByProduct((int)Tools::getValue('id_product'), Context::getContext()->language->id), - 'averages' => $averages, - 'product_comment_path' => $this->_path, - 'averageTotal' => $averageTotal, - 'allow_guests' => (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'), - 'too_early' => ($customerComment && (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()), - 'delay' => Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME'))); - - $this->context->controller->pagination((int)ProductComment::getCommentNumber((int)Tools::getValue('id_product'))); - $image = Product::getCover((int)Tools::getValue('id_product')); - Context::getContext()->smarty->assign(array( + $this->context->smarty->assign(array( + 'logged' => (int)$this->context->customer->isLogged(true), + 'action_url' => '', + 'comments' => ProductComment::getByProduct((int)Tools::getValue('id_product'), 1, null, $this->context->cookie->id_customer), + 'criterions' => ProductCommentCriterion::getByProduct((int)Tools::getValue('id_product'), $this->context->language->id), + 'averages' => $averages, + 'product_comment_path' => $this->_path, + 'averageTotal' => $averageTotal, + 'allow_guests' => (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'), + 'too_early' => ($customerComment && (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()), + 'delay' => Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME'), 'id_product_comment_form' => (int)Tools::getValue('id_product'), 'secure_key' => $this->secure_key, 'productcomment_cover' => (int)Tools::getValue('id_product').'-'.(int)$image['id_image'], 'mediumSize' => Image::getSize('medium'), - 'nbComments' => (int)ProductComment::getCommentNumber((int)Tools::getValue('id_product')) + 'nbComments' => (int)ProductComment::getCommentNumber((int)Tools::getValue('id_product')), + 'productcomments_controller_url' => $this->context->link->getModuleLink('productcomments') )); + $this->context->controller->pagination((int)ProductComment::getCommentNumber((int)Tools::getValue('id_product'))); + return ($this->display(__FILE__, '/productcomments.tpl')); } public function hookHeader() { $this->context->controller->addCSS($this->_path.'productcomments.css', 'all'); - $this->context->controller->addJS($this->_path.'js/jquery.rating.pack.js'); - $this->context->controller->addJS($this->_path.'js/jquery.textareaCounter.plugin.js'); - $this->_frontOfficePostProcess(); } public function hookExtraProductComparison($params) @@ -784,8 +780,8 @@ class ProductComments extends Module foreach ($params['list_ids_product'] as $id_product) { - $grades = ProductComment::getAveragesByProduct($id_product, Context::getContext()->language->id); - $criterions = ProductCommentCriterion::getByProduct($id_product, Context::getContext()->language->id); + $grades = ProductComment::getAveragesByProduct($id_product, $this->context->language->id); + $criterions = ProductCommentCriterion::getByProduct($id_product, $this->context->language->id); $grade_total = 0; if (count($grades) > 0) { @@ -811,9 +807,9 @@ class ProductComments extends Module if (count($list_grades) < 1) return false; - Context::getContext()->smarty->assign(array('grades' => $list_grades, 'product_grades' => $list_product_grades, 'list_ids_product' => $params['list_ids_product'], + $this->context->smarty->assign(array('grades' => $list_grades, 'product_grades' => $list_product_grades, 'list_ids_product' => $params['list_ids_product'], 'list_product_average' => $list_product_average, 'product_comments' => $list_product_comment)); return $this->display(__FILE__, '/products-comparison.tpl'); } -} \ No newline at end of file +} diff --git a/modules/productcomments/productcomments.tpl b/modules/productcomments/productcomments.tpl index c12738c7d..f3d0af038 100644 --- a/modules/productcomments/productcomments.tpl +++ b/modules/productcomments/productcomments.tpl @@ -23,98 +23,10 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} -
    @@ -148,10 +60,10 @@ {/if} {if $logged == 1} {if !$comment.customer_advice} -
  • {l s='Was this comment useful to you?' mod='productcomments'}
  • +
  • {l s='Was this comment useful to you?' mod='productcomments'}
  • {/if} {if !$comment.customer_report} -
  • {l s='Report abuse' mod='productcomments'}
  • +
  • {l s='Report abuse' mod='productcomments'}
  • {/if} {/if} @@ -161,69 +73,74 @@ {/foreach} {else} {if ($too_early == false AND ($logged OR $allow_guests))} -
    -

    {l s='Write your review' mod='productcomments'}

    -
    - {$product->name|escape:html:'UTF-8'} -
    -

    {$product->name}

    - {$product->description_short} -
    -
    - -
    -

    {l s='Write your review' mod='productcomments'}

    - {if $criterions|@count > 0} -
    - {section loop=$criterions name=i start=0 step=1} - - - {$criterions[i].name|escape:'html':'UTF-8'}:  - -
    - - - - - +
    +

    {l s='Write your review' mod='productcomments'}

    +
    + {$product->name|escape:html:'UTF-8'} +
    +

    {$product->name}

    + {$product->description_short}
    - {/section}
    - {/if} -
    -

    - - -

    -

    - - -

    - {if $allow_guests == true && $logged == 0} -

    - - -

    + +
    +

    {l s='Write your review' mod='productcomments'}

    + + + + {if $criterions|@count > 0} +
      + {foreach from=$criterions item='criterion'} +
    • + +
      + + + + + +
      +
      +
    • + {/foreach} +
    {/if} -

    - * {l s='Required fields' mod='productcomments'} + + + + + + + + {if $allow_guests == true && $logged == 0} + + + {/if} + +

    -
    +

    - {l s='Be the first to write your review' mod='productcomments'} ! + {l s='Be the first to write your review' mod='productcomments'} !

    {else}

    {l s='No customer comments for the moment.' mod='productcomments'}

    {/if} {/if}
    -
    \ No newline at end of file +
    diff --git a/modules/productcomments/translations/fr.php b/modules/productcomments/translations/fr.php index 584acf8d0..5dc752354 100644 --- a/modules/productcomments/translations/fr.php +++ b/modules/productcomments/translations/fr.php @@ -2,23 +2,18 @@ global $_MODULE; $_MODULE = array(); +$_MODULE['<{productcomments}prestashop>productcommentcriterion_a09ed6c60eb3213939cecb4c580813cd'] = 'Disponible pour le catalogue entier'; +$_MODULE['<{productcomments}prestashop>productcommentcriterion_467366059d7d7c743a4d0971363a8d66'] = 'Restreint à certaines catégories'; +$_MODULE['<{productcomments}prestashop>productcommentcriterion_772911becd336c843ab09a1d4b4f66c0'] = 'Restreint à certains produits'; $_MODULE['<{productcomments}prestashop>productcomments-ajax_fd4b5401d4d3c7d32d158bfc1e552f3b'] = 'Veuillez donner votre nom'; $_MODULE['<{productcomments}prestashop>productcomments-ajax_f88dc17737f7fdd4464b2eb922a8f133'] = 'Une erreur s\'est produite lors de l\'enregistrement de votre commentaire.'; $_MODULE['<{productcomments}prestashop>productcomments-ajax_7fa4a3510dafd0eac6435c19861b2bb7'] = 'Commentaire publié.'; $_MODULE['<{productcomments}prestashop>productcomments-ajax_f8694a9aae2eb045920f613cfa7f1235'] = 'En attente de la validation de la modération.'; $_MODULE['<{productcomments}prestashop>productcomments-ajax_6bf852d9850445291f5e9d4740ac7b50'] = 'Un texte de commentaire est nécessaire.'; $_MODULE['<{productcomments}prestashop>productcomments-ajax_8aafe254c3e8dceb6425591b322044f2'] = 'Vous devriez attendre %d secondes avant de publier un nouveau commentaire.'; -$_MODULE['<{productcomments}prestashop>productcomments-extra_3f3c57ad486f74745aef0a3bb5f3ad6c'] = 'Votre commentaire ne peut pas être publié. Veuillez remplir tous les champs requis.'; $_MODULE['<{productcomments}prestashop>productcomments-extra_7c3b0e9898b88deee7ea75aafd2e37e2'] = 'Note moyenne'; $_MODULE['<{productcomments}prestashop>productcomments-extra_a71a0229e164fecdcde3c4e0f40473fa'] = 'Lire les avis utilisateurs'; $_MODULE['<{productcomments}prestashop>productcomments-extra_7966126831926ad29c528b239d69f855'] = 'Donnez votre avis'; -$_MODULE['<{productcomments}prestashop>productcomments-extra_b78a3223503896721cca1303f776159b'] = 'Titre'; -$_MODULE['<{productcomments}prestashop>productcomments-extra_0be8406951cdfda82f00f79328cf4efc'] = 'Commentaire'; -$_MODULE['<{productcomments}prestashop>productcomments-extra_221e705c06e231636fdbccfdd14f4d5c'] = 'Votre nom'; -$_MODULE['<{productcomments}prestashop>productcomments-extra_ea4788705e6873b424c65e91c2846b19'] = 'Annuler'; -$_MODULE['<{productcomments}prestashop>productcomments-extra_e81c4e4f2b7b93b481e13a8553c2ae1b'] = 'ou'; -$_MODULE['<{productcomments}prestashop>productcomments-extra_94966d90747b97d1f0f206c98a8b1ac3'] = 'Envoyer'; -$_MODULE['<{productcomments}prestashop>productcomments-extra_70397c4b252a5168c5ec003931cea215'] = 'Champs requis'; $_MODULE['<{productcomments}prestashop>productcomments_b91c4e8b229a399a3bc911d352524a9b'] = 'Commentaires produits'; $_MODULE['<{productcomments}prestashop>productcomments_9918811c511f3481c085e46c07ab5da8'] = 'Permet aux client de commenter les produits.'; $_MODULE['<{productcomments}prestashop>productcomments_c888438d14855d7d96a2724ee9c306bd'] = 'Configuration mise à jour'; @@ -88,3 +83,12 @@ $_MODULE['<{productcomments}prestashop>products-comparison_8413c683b4b27cc3f4dbd $_MODULE['<{productcomments}prestashop>products-comparison_b1897515d548a960afe49ecf66a29021'] = 'Moyenne'; $_MODULE['<{productcomments}prestashop>products-comparison_bc976f6c3405523cde61f63a7cbe224b'] = 'Voir les avis'; $_MODULE['<{productcomments}prestashop>tab_8413c683b4b27cc3f4dbd4c90329d8ba'] = 'Commentaires'; +$_MODULE['<{productcomments}prestashop>default_607d7adc590bb9a615b6fa5bc8a4f2f6'] = 'ID produit est incorrect'; +$_MODULE['<{productcomments}prestashop>default_7b0bf23ae4079e07a3a4cb4d07e2caef'] = 'Le titre est incorrect'; +$_MODULE['<{productcomments}prestashop>default_ddbd56de5feb78ef1aaf60401f8c472b'] = 'Le commentaire est incorrect'; +$_MODULE['<{productcomments}prestashop>default_1b1030b6294e9096a7d7c40d83d61872'] = 'Le nom est incorrect'; +$_MODULE['<{productcomments}prestashop>default_a95dff703b20b1e705210c39b3865bf0'] = 'Vous devez être connecter afin de poster un commentaire'; +$_MODULE['<{productcomments}prestashop>default_a201fbadca94d310a1b62407cdc775d5'] = 'Vous devez donner une note'; +$_MODULE['<{productcomments}prestashop>default_dfbe69c6d9568ecb0e65e7b32ed92a3a'] = 'Le produit n\'a pas été trouvé'; +$_MODULE['<{productcomments}prestashop>default_6d28f2900adb9e500868166f6d04da92'] = 'Vous devez patienter'; +$_MODULE['<{productcomments}prestashop>default_ba8d7ae5dcadfba739f28a777378f208'] = 'secondes avant de poster un nouveau commentaire';