diff --git a/ProductComment.php b/ProductComment.php index bfd38822..9d5cd015 100644 --- a/ProductComment.php +++ b/ProductComment.php @@ -95,6 +95,7 @@ public static function getByProduct($id_product, $p = 1, $n = null, $id_customer $validate = (bool) Configuration::get('PRODUCT_COMMENTS_MODERATE'); $p = (int) $p; $n = (int) $n; + $id_customer = (int) $id_customer; if ($p <= 1) { $p = 1; } @@ -102,20 +103,20 @@ public static function getByProduct($id_product, $p = 1, $n = null, $id_customer $n = 5; } - $cache_id = 'ProductComment::getByProduct_' . (int) $id_product . '-' . (int) $p . '-' . (int) $n . '-' . (int) $id_customer . '-' . (bool) $validate; + $cache_id = 'ProductComment::getByProduct_' . $id_product . '-' . $p . '-' . $n . '-' . $id_customer . '-' . $validate; if (!Cache::isStored($cache_id)) { $result = Db::getInstance((bool) _PS_USE_SQL_SLAVE_)->executeS(' SELECT pc.`id_product_comment`, - (SELECT count(*) FROM `' . _DB_PREFIX_ . 'product_comment_usefulness` pcu WHERE pcu.`id_product_comment` = pc.`id_product_comment` AND pcu.`usefulness` = 1) as total_useful, - (SELECT count(*) FROM `' . _DB_PREFIX_ . 'product_comment_usefulness` pcu WHERE pcu.`id_product_comment` = pc.`id_product_comment`) as total_advice, ' . - ((int) $id_customer ? '(SELECT count(*) FROM `' . _DB_PREFIX_ . 'product_comment_usefulness` pcuc WHERE pcuc.`id_product_comment` = pc.`id_product_comment` AND pcuc.id_customer = ' . (int) $id_customer . ') as customer_advice, ' : '') . - ((int) $id_customer ? '(SELECT count(*) FROM `' . _DB_PREFIX_ . 'product_comment_report` pcrc WHERE pcrc.`id_product_comment` = pc.`id_product_comment` AND pcrc.id_customer = ' . (int) $id_customer . ') as customer_report, ' : '') . ' + (SELECT count(*) FROM `' . _DB_PREFIX_ . 'product_comment_usefulness` pcu WHERE pcu.`id_product_comment` = pc.`id_product_comment` AND pcu.`usefulness` = 1) AS total_useful, + (SELECT count(*) FROM `' . _DB_PREFIX_ . 'product_comment_usefulness` pcu WHERE pcu.`id_product_comment` = pc.`id_product_comment`) AS total_advice, ' . + ($id_customer ? '(SELECT count(*) FROM `' . _DB_PREFIX_ . 'product_comment_usefulness` pcuc WHERE pcuc.`id_product_comment` = pc.`id_product_comment` AND pcuc.id_customer = ' . $id_customer . ') AS customer_advice, ' : '') . + ($id_customer ? '(SELECT count(*) FROM `' . _DB_PREFIX_ . 'product_comment_report` pcrc WHERE pcrc.`id_product_comment` = pc.`id_product_comment` AND pcrc.id_customer = ' . $id_customer . ') AS customer_report, ' : '') . ' IF(c.id_customer, CONCAT(c.`firstname`, \' \', LEFT(c.`lastname`, 1)), pc.customer_name) customer_name, pc.`content`, pc.`grade`, pc.`date_add`, pc.title FROM `' . _DB_PREFIX_ . 'product_comment` pc LEFT JOIN `' . _DB_PREFIX_ . 'customer` c ON c.`id_customer` = pc.`id_customer` - WHERE pc.`id_product` = ' . (int) ($id_product) . ($validate ? ' AND pc.`validate` = 1' : '') . ' + WHERE pc.`id_product` = ' . $id_product . ($validate ? ' AND pc.`validate` = 1' : '') . ' ORDER BY pc.`date_add` DESC - ' . ($n ? 'LIMIT ' . (int) (($p - 1) * $n) . ', ' . (int) ($n) : '')); + ' . ($n ? 'LIMIT ' . (($p - 1) * $n) . ', ' . $n : '')); Cache::store($cache_id, $result); } @@ -169,8 +170,8 @@ public static function getGradeByProduct($id_product, $id_lang) LEFT JOIN `' . _DB_PREFIX_ . 'product_comment_grade` pcg ON (pcg.`id_product_comment` = pc.`id_product_comment`) LEFT JOIN `' . _DB_PREFIX_ . 'product_comment_criterion` pcc ON (pcc.`id_product_comment_criterion` = pcg.`id_product_comment_criterion`) LEFT JOIN `' . _DB_PREFIX_ . 'product_comment_criterion_lang` pccl ON (pccl.`id_product_comment_criterion` = pcg.`id_product_comment_criterion`) - WHERE pc.`id_product` = ' . (int) $id_product . ' - AND pccl.`id_lang` = ' . (int) $id_lang . + WHERE pc.`id_product` = ' . $id_product . ' + AND pccl.`id_lang` = ' . $id_lang . ($validate ? ' AND pc.`validate` = 1' : '')); } @@ -178,7 +179,7 @@ public static function getRatings($id_product) { $validate = Configuration::get('PRODUCT_COMMENTS_MODERATE'); - $sql = 'SELECT (SUM(pc.`grade`) / COUNT(pc.`grade`)) AS avg, + $sql = 'SELECT AVG(pc.`grade`) AS avg, MIN(pc.`grade`) AS min, MAX(pc.`grade`) AS max FROM `' . _DB_PREFIX_ . 'product_comment` pc @@ -194,7 +195,7 @@ public static function getAverageGrade($id_product) $validate = Configuration::get('PRODUCT_COMMENTS_MODERATE'); return Db::getInstance((bool) _PS_USE_SQL_SLAVE_)->getRow(' - SELECT (SUM(pc.`grade`) / COUNT(pc.`grade`)) AS grade + SELECT AVG(pc.`grade`) AS grade FROM `' . _DB_PREFIX_ . 'product_comment` pc WHERE pc.`id_product` = ' . (int) $id_product . ' AND pc.`deleted` = 0' . @@ -241,12 +242,12 @@ public static function getCommentNumber($id_product) return false; } $validate = (bool) Configuration::get('PRODUCT_COMMENTS_MODERATE'); - $cache_id = 'ProductComment::getCommentNumber_' . (int) $id_product . '-' . $validate; + $cache_id = 'ProductComment::getCommentNumber_' . $id_product . '-' . $validate; if (!Cache::isStored($cache_id)) { $result = (int) Db::getInstance((bool) _PS_USE_SQL_SLAVE_)->getValue(' SELECT COUNT(`id_product_comment`) AS "nbr" FROM `' . _DB_PREFIX_ . 'product_comment` pc - WHERE `id_product` = ' . (int) ($id_product) . ($validate ? ' AND `validate` = 1' : '')); + WHERE `id_product` = ' . $id_product . ($validate ? ' AND `validate` = 1' : '')); Cache::store($cache_id, (string) $result); } @@ -268,7 +269,7 @@ public static function getGradedCommentNumber($id_product) $result = Db::getInstance((bool) _PS_USE_SQL_SLAVE_)->getRow(' SELECT COUNT(pc.`id_product`) AS nbr FROM `' . _DB_PREFIX_ . 'product_comment` pc - WHERE `id_product` = ' . (int) ($id_product) . ($validate == '1' ? ' AND `validate` = 1' : '') . ' + WHERE `id_product` = ' . $id_product . ($validate == '1' ? ' AND `validate` = 1' : '') . ' AND `grade` > 0'); return (int) ($result['nbr']); @@ -348,7 +349,7 @@ public function validate($validate = '1') $success = (Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'product_comment` SET `validate` = ' . (int) $validate . ' - WHERE `id_product_comment` = ' . (int) $this->id)); + WHERE `id_product_comment` = ' . $this->id)); Hook::exec('actionObjectProductCommentValidateAfter', ['object' => $this]); @@ -381,7 +382,7 @@ public static function deleteGrades($id_product_comment) return Db::getInstance()->execute(' DELETE FROM `' . _DB_PREFIX_ . 'product_comment_grade` - WHERE `id_product_comment` = ' . (int) $id_product_comment); + WHERE `id_product_comment` = ' . $id_product_comment); } /** @@ -397,7 +398,7 @@ public static function deleteReports($id_product_comment) return Db::getInstance()->execute(' DELETE FROM `' . _DB_PREFIX_ . 'product_comment_report` - WHERE `id_product_comment` = ' . (int) $id_product_comment); + WHERE `id_product_comment` = ' . $id_product_comment); } /** @@ -413,7 +414,7 @@ public static function deleteUsefulness($id_product_comment) return Db::getInstance()->execute(' DELETE FROM `' . _DB_PREFIX_ . 'product_comment_usefulness` - WHERE `id_product_comment` = ' . (int) $id_product_comment); + WHERE `id_product_comment` = ' . $id_product_comment); } /** diff --git a/ProductCommentCriterion.php b/ProductCommentCriterion.php index 7c400468..e1c0e538 100644 --- a/ProductCommentCriterion.php +++ b/ProductCommentCriterion.php @@ -105,7 +105,7 @@ public function addProduct($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 . ') + VALUES(' . (int) $this->id . ',' . $id_product . ') '); } @@ -122,7 +122,7 @@ public function addCategory($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 . ') + VALUES(' . (int) $this->id . ',' . $id_category . ') '); } @@ -145,7 +145,7 @@ public function addGrade($id_product_comment, $grade) return Db::getInstance()->execute(' INSERT INTO `' . _DB_PREFIX_ . 'product_comment_grade` (`id_product_comment`, `id_product_comment_criterion`, `grade`) VALUES( - ' . (int) ($id_product_comment) . ', + ' . $id_product_comment . ', ' . (int) $this->id . ', ' . (int) ($grade) . ')'); } @@ -169,7 +169,7 @@ public static function getByProduct($id_product, $id_lang) $alias = 'ps'; } - $cache_id = 'ProductCommentCriterion::getByProduct_' . (int) $id_product . '-' . (int) $id_lang; + $cache_id = 'ProductCommentCriterion::getByProduct_' . $id_product . '-' . $id_lang; if (!Cache::isStored($cache_id)) { $result = Db::getInstance()->executeS(' SELECT pcc.`id_product_comment_criterion`, pccl.`name` @@ -177,12 +177,12 @@ public static function getByProduct($id_product, $id_lang) 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 . ') + ON (pcc.`id_product_comment_criterion` = pccp.`id_product_comment_criterion` AND pccp.`id_product` = ' . $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) . ' + ON (' . $alias . '.id_category_default = pccc.id_category AND ' . $alias . '.id_product = ' . $id_product . ') + WHERE pccl.`id_lang` = ' . $id_lang . ' AND ( pccp.id_product IS NOT NULL OR ps.id_product IS NOT NULL @@ -212,7 +212,7 @@ public static function getCriterions($id_lang, $type = false, $active = false) 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 : '') . ' + WHERE pccl.`id_lang` = ' . $id_lang . ($active ? ' AND active = 1' : '') . ($type ? ' AND id_product_comment_criterion_type = ' . (int) $type : '') . ' ORDER BY pccl.`name` ASC'; $criterions = Db::getInstance()->executeS($sql); diff --git a/config.xml b/config.xml index ba573009..7ed9bb20 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ productcomments - + diff --git a/controllers/front/ListComments.php b/controllers/front/ListComments.php index feeca5f8..888650b7 100644 --- a/controllers/front/ListComments.php +++ b/controllers/front/ListComments.php @@ -64,20 +64,20 @@ public function display() $productComment['content'] = htmlentities($productComment['content']); $productComment['date_add'] = $dateFormatter->format($dateAdd); - if ($isLastNameAnonymous && isset($productComment['lastname'])) { - $productComment['lastname'] = substr($productComment['lastname'], 0, 1) . '.'; - } + // The customer has firstname and lastname, for guest we only have customer_name field + $productComment['customer_name'] = !empty($productComment['customer_name']) + ? $productComment['customer_name'] + : $productComment['firstname'] . ' ' . $productComment['lastname']; - // if registered customer : return customer first and last name instead of using customer_name - if (!empty($productComment['lastname'])) { - $productComment['customer_name'] = htmlentities($productComment['firstname'] . ' ' . $productComment['lastname']); - } else { - $productComment['customer_name'] = htmlentities($productComment['customer_name']); + if ($isLastNameAnonymous) { + $productComment['customer_name'] = $this->anonymizeName($productComment['customer_name']); } + $productComment['customer_name'] = htmlentities($productComment['customer_name']); + $usefulness = $productCommentRepository->getProductCommentUsefulness($productComment['id_product_comment']); $productComment = array_merge($productComment, $usefulness); - if (empty($productComment['customer_name']) && !isset($productComment['firstname']) && !isset($productComment['lastname'])) { + if (empty($productComment['customer_name'])) { $productComment['customer_name'] = $this->trans('Deleted account', [], 'Modules.Productcomments.Shop'); } @@ -91,4 +91,22 @@ public function display() ) ); } + + /** + * Anonymize the user's last name. Display only initials, e.g. John D. + * + * @param string $name + */ + private function anonymizeName($name) + { + $parts = explode(' ', $name); + $firstName = $parts[0]; + $lastName = count($parts) > 1 ? array_pop($parts) : ''; + $name = $firstName; + if (!empty($lastName)) { + $name .= ' ' . mb_substr($lastName, 0, 1, 'UTF-8') . '.'; + } + + return $name; + } } diff --git a/logo.gif b/logo.gif deleted file mode 100644 index 39433cf7..00000000 Binary files a/logo.gif and /dev/null differ diff --git a/productcomments.php b/productcomments.php index 0a0bb76a..fb9ee754 100644 --- a/productcomments.php +++ b/productcomments.php @@ -45,7 +45,7 @@ public function __construct() { $this->name = 'productcomments'; $this->tab = 'front_office_features'; - $this->version = '5.0.2'; + $this->version = '5.0.3'; $this->author = 'PrestaShop'; $this->need_instance = 0; $this->bootstrap = true; @@ -164,13 +164,34 @@ public function getCacheId($id_product = null) protected function _postProcess() { if (Tools::isSubmit('submitModerate')) { - Configuration::updateValue('PRODUCT_COMMENTS_MODERATE', (int) Tools::getValue('PRODUCT_COMMENTS_MODERATE')); - Configuration::updateValue('PRODUCT_COMMENTS_ALLOW_GUESTS', (int) Tools::getValue('PRODUCT_COMMENTS_ALLOW_GUESTS')); - Configuration::updateValue('PRODUCT_COMMENTS_USEFULNESS', (int) Tools::getValue('PRODUCT_COMMENTS_USEFULNESS')); - Configuration::updateValue('PRODUCT_COMMENTS_COMMENTS_PER_PAGE', (int) Tools::getValue('PRODUCT_COMMENTS_COMMENTS_PER_PAGE')); - Configuration::updateValue('PRODUCT_COMMENTS_ANONYMISATION', (int) Tools::getValue('PRODUCT_COMMENTS_ANONYMISATION')); - Configuration::updateValue('PRODUCT_COMMENTS_MINIMAL_TIME', (int) Tools::getValue('PRODUCT_COMMENTS_MINIMAL_TIME')); - $this->_html .= '
' . $this->trans('Settings updated', [], 'Modules.Productcomments.Admin') . '
'; + $errors = []; + $productCommentsMinimalTime = Tools::getValue('PRODUCT_COMMENTS_MINIMAL_TIME'); + if (!Validate::isUnsignedInt($productCommentsMinimalTime) || 0 >= $productCommentsMinimalTime) { + $errors[] = $this->trans( + '%s is invalid. Please enter an integer greater than %s.', + [$this->trans('Minimum time between 2 reviews from the same user', [], 'Modules.Productcomments.Admin'), '0'], + 'Admin.Notifications.Error' + ); + } + $productCommentsPerPage = Tools::getValue('PRODUCT_COMMENTS_COMMENTS_PER_PAGE'); + if (!Validate::isUnsignedInt($productCommentsPerPage) || 0 >= $productCommentsPerPage) { + $errors[] = $this->trans( + '%s is invalid. Please enter an integer greater than %s.', + [$this->trans('Number of comments per page', [], 'Modules.Productcomments.Admin'), '0'], + 'Admin.Notifications.Error' + ); + } + if (count($errors)) { + $this->_html .= $this->displayError(implode('
', $errors)); + } else { + Configuration::updateValue('PRODUCT_COMMENTS_MODERATE', (int) Tools::getValue('PRODUCT_COMMENTS_MODERATE')); + Configuration::updateValue('PRODUCT_COMMENTS_ALLOW_GUESTS', (int) Tools::getValue('PRODUCT_COMMENTS_ALLOW_GUESTS')); + Configuration::updateValue('PRODUCT_COMMENTS_USEFULNESS', (int) Tools::getValue('PRODUCT_COMMENTS_USEFULNESS')); + Configuration::updateValue('PRODUCT_COMMENTS_ANONYMISATION', (int) Tools::getValue('PRODUCT_COMMENTS_ANONYMISATION')); + Configuration::updateValue('PRODUCT_COMMENTS_MINIMAL_TIME', $productCommentsMinimalTime); + Configuration::updateValue('PRODUCT_COMMENTS_COMMENTS_PER_PAGE', $productCommentsPerPage); + $this->_html .= $this->displayConfirmation($this->trans('Settings updated', [], 'Modules.Productcomments.Admin')); + } } elseif (Tools::isSubmit('productcomments')) { $id_product_comment = (int) Tools::getValue('id_product_comment'); $comment = new ProductComment($id_product_comment); @@ -193,7 +214,7 @@ protected function _postProcess() $criterion->name = $name; if (!$criterion->validateFields(false) || !$criterion->validateFieldsLang(false)) { - $this->_html .= '
' . $this->trans('The criterion cannot be saved', [], 'Modules.Productcomments.Admin') . '
'; + $this->_html .= $this->displayError($this->trans('The criterion cannot be saved', [], 'Modules.Productcomments.Admin')); } else { $criterion->save(); @@ -220,14 +241,14 @@ protected function _postProcess() if ($criterion->save()) { Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminModules', true, [], ['configure' => $this->name, 'conf' => 4])); } else { - $this->_html .= '
' . $this->trans('The criterion cannot be saved', [], 'Modules.Productcomments.Admin') . '
'; + $this->_html .= $this->displayError($this->trans('The criterion cannot be saved', [], 'Modules.Productcomments.Admin')); } } } elseif (Tools::isSubmit('deleteproductcommentscriterion')) { $productCommentCriterion = new ProductCommentCriterion((int) Tools::getValue('id_product_comment_criterion')); if ($productCommentCriterion->id) { if ($productCommentCriterion->delete()) { - $this->_html .= '
' . $this->trans('Criterion deleted', [], 'Modules.Productcomments.Admin') . '
'; + $this->_html .= $this->displayConfirmation($this->trans('Criterion deleted', [], 'Modules.Productcomments.Admin')); } } } elseif (Tools::isSubmit('statusproductcommentscriterion')) { @@ -410,7 +431,6 @@ public function renderConfigForm() public function renderModerateLists() { - require_once dirname(__FILE__) . '/ProductComment.php'; $return = null; if (Configuration::get('PRODUCT_COMMENTS_MODERATE')) { @@ -418,12 +438,7 @@ public function renderModerateLists() $fields_list = $this->getStandardFieldList(); - if (version_compare(_PS_VERSION_, '1.6', '<')) { - $return .= '

' . $this->trans('Reviews waiting for approval', [], 'Modules.Productcomments.Admin') . '

'; - $actions = ['enable', 'delete']; - } else { - $actions = ['approve', 'delete']; - } + $actions = ['approve', 'delete']; $helper = new HelperList(); $helper->list_id = 'form-productcomments-moderate-list'; @@ -511,8 +526,6 @@ public function displayNoabuseLink($token, $id, $name = null) public function renderCriterionList() { - include_once dirname(__FILE__) . '/ProductCommentCriterion.php'; - $criterions = ProductCommentCriterion::getCriterions($this->context->language->id, false, false); $fields_list = [ @@ -556,8 +569,6 @@ public function renderCriterionList() public function renderCommentsList() { - require_once dirname(__FILE__) . '/ProductComment.php'; - $fields_list = $this->getStandardFieldList(); $helper = new HelperList(); @@ -712,45 +723,36 @@ public function renderCriterionForm($id_criterion = 0) } } - if (version_compare(_PS_VERSION_, '1.6', '<')) { - $field_category_tree = [ - 'type' => 'categories_select', - 'name' => 'categoryBox', - 'label' => $this->trans('Criterion will be restricted to the following categories', [], 'Modules.Productcomments.Admin'), - 'category_tree' => $this->initCategoriesAssociation(null, $id_criterion), - ]; - } else { - $field_category_tree = [ - 'type' => 'categories', - 'label' => $this->trans('Criterion will be restricted to the following categories', [], 'Modules.Productcomments.Admin'), - 'name' => 'categoryBox', - 'desc' => $this->trans('Mark the boxes of categories to which this criterion applies.', [], 'Modules.Productcomments.Admin'), - 'tree' => [ - 'use_search' => false, - 'id' => 'categoryBox', - 'use_checkbox' => true, - 'selected_categories' => $selected_categories, - ], - //retro compat 1.5 for category tree - 'values' => [ - 'trads' => [ - 'Root' => Category::getTopCategory(), - 'selected' => $this->trans('Selected', [], 'Modules.Productcomments.Admin'), - 'Collapse All' => $this->trans('Collapse All', [], 'Modules.Productcomments.Admin'), - 'Expand All' => $this->trans('Expand All', [], 'Modules.Productcomments.Admin'), - 'Check All' => $this->trans('Check All', [], 'Modules.Productcomments.Admin'), - 'Uncheck All' => $this->trans('Uncheck All', [], 'Modules.Productcomments.Admin'), - ], - 'selected_cat' => $selected_categories, - 'input_name' => 'categoryBox[]', - 'use_radio' => false, - 'use_search' => false, - 'disabled_categories' => [], - 'top_category' => Category::getTopCategory(), - 'use_context' => true, + $field_category_tree = [ + 'type' => 'categories', + 'label' => $this->trans('Criterion will be restricted to the following categories', [], 'Modules.Productcomments.Admin'), + 'name' => 'categoryBox', + 'desc' => $this->trans('Mark the boxes of categories to which this criterion applies.', [], 'Modules.Productcomments.Admin'), + 'tree' => [ + 'use_search' => false, + 'id' => 'categoryBox', + 'use_checkbox' => true, + 'selected_categories' => $selected_categories, + ], + //retro compat 1.5 for category tree + 'values' => [ + 'trads' => [ + 'Root' => Category::getTopCategory(), + 'selected' => $this->trans('Selected', [], 'Modules.Productcomments.Admin'), + 'Collapse All' => $this->trans('Collapse All', [], 'Modules.Productcomments.Admin'), + 'Expand All' => $this->trans('Expand All', [], 'Modules.Productcomments.Admin'), + 'Check All' => $this->trans('Check All', [], 'Modules.Productcomments.Admin'), + 'Uncheck All' => $this->trans('Uncheck All', [], 'Modules.Productcomments.Admin'), ], - ]; - } + 'selected_cat' => $selected_categories, + 'input_name' => 'categoryBox[]', + 'use_radio' => false, + 'use_search' => false, + 'disabled_categories' => [], + 'top_category' => Category::getTopCategory(), + 'use_context' => true, + ], + ]; $fields_form_1 = [ 'form' => [ diff --git a/src/Repository/ProductCommentRepository.php b/src/Repository/ProductCommentRepository.php index dfdfd19b..a1e0d1a3 100644 --- a/src/Repository/ProductCommentRepository.php +++ b/src/Repository/ProductCommentRepository.php @@ -153,7 +153,7 @@ public function getAverageGrade($productId, $validatedOnly) /** @var QueryBuilder $qb */ $qb = $this->connection->createQueryBuilder(); $qb - ->select('SUM(pc.grade) / COUNT(pc.grade) AS averageGrade') + ->select('AVG(pc.grade) AS averageGrade') ->from($this->databasePrefix . 'product_comment', 'pc') ->andWhere('pc.id_product = :id_product') ->andWhere('pc.deleted = :deleted') diff --git a/tests/phpstan/phpstan-latest.neon b/tests/phpstan/phpstan-latest.neon index d29f77ca..c604f7c7 100644 --- a/tests/phpstan/phpstan-latest.neon +++ b/tests/phpstan/phpstan-latest.neon @@ -1,9 +1,2 @@ includes: - %currentWorkingDirectory%/tests/phpstan/phpstan.neon - -parameters: - ignoreErrors: - - '#Access to an undefined property Cookie::\$id_customer.#' - - '#Access to an undefined property Cookie::\$id_guest.#' - - '#Access to an undefined property HelperList::\$list_id.#' - - '#Access to an undefined property HelperList::\$shopLinkType.#' diff --git a/views/css/productcomments.css b/views/css/productcomments.css index dca85682..ab40df51 100644 --- a/views/css/productcomments.css +++ b/views/css/productcomments.css @@ -123,7 +123,7 @@ padding: 15px 30px 30px; } -.product-comment-modal .modal-header h2 { +.product-comment-modal .modal-header .h2 { float: left; font-size: 20px; } @@ -133,7 +133,7 @@ max-width: 774px; } -.product-comment-modal .modal-dialog h3 { +.product-comment-modal .modal-dialog .h3 { font-size: 14px; } @@ -357,7 +357,7 @@ margin-bottom: 20px; } -.product-comment-list-item .comment-content h4 { +.product-comment-list-item .comment-content .h4 { height: 22px; color: #363a41; font-size: 16px; diff --git a/views/templates/hook/alert-modal.tpl b/views/templates/hook/alert-modal.tpl index 314fc87a..ba67fe9f 100644 --- a/views/templates/hook/alert-modal.tpl +++ b/views/templates/hook/alert-modal.tpl @@ -23,8 +23,8 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) *} -{assign var='icon' value=$icon|default:'check_circle'} -{assign var='modal_message' value=$modal_message|default:''} +{$icon = $icon|default:'check_circle'} +{$modal_message = $modal_message|default:''} -
-
-
- - {l s='Comments' d='Modules.Productcomments.Shop'} ({$nb_comments}) -
- {include file='module:productcomments/views/templates/hook/average-grade-stars.tpl' grade=$average_grade} +
+
+ + {l s='Comments' d='Modules.Productcomments.Shop'} ({$nb_comments})
+ {include file='module:productcomments/views/templates/hook/average-grade-stars.tpl' grade=$average_grade}
{include file='module:productcomments/views/templates/hook/product-comment-item-prototype.tpl' assign="comment_prototype"} {include file='module:productcomments/views/templates/hook/empty-product-comment.tpl'} -
-
-
+ +
-
- + + {* Appreciation post error modal *} diff --git a/views/templates/hook/product-list-reviews.tpl b/views/templates/hook/product-list-reviews.tpl index 0aeb2a8e..bf465b5b 100644 --- a/views/templates/hook/product-list-reviews.tpl +++ b/views/templates/hook/product-list-reviews.tpl @@ -29,11 +29,3 @@
- -{if $nb_comments != 0} -{* Rich snippet rating is displayed via php/smarty meaning it will be cached (for example on homepage) *} -
- - -
-{/if}