Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 5.0.3 #156

Merged
merged 47 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
cfcf14d
Simplify Average code
leemyongpakvn Jun 11, 2022
30b1771
Simplify Average code
leemyongpakvn Jun 11, 2022
cd6afab
Remove redundant open parenthesis
leemyongpakvn Jun 18, 2022
243fcd5
Simplify Type casting
leemyongpakvn Jun 19, 2022
2953c4c
Remove redandunt type caft left by previous commit
leemyongpakvn Jun 20, 2022
6734217
Update ProductComment.php
leemyongpakvn Jun 20, 2022
285bd63
Update ProductCommentCriterion.php
leemyongpakvn Jun 24, 2022
59103ec
Add validation for 2 positive integer fields
leemyongpakvn Jul 1, 2022
8f7ce5f
tweak spaces
leemyongpakvn Jul 1, 2022
accf14a
tweak spaces again
leemyongpakvn Jul 1, 2022
d140f77
Update with php-cs-fixer fixed content
leemyongpakvn Jul 3, 2022
4cde940
cs-fixer
leemyongpakvn Jul 6, 2022
c65ab2a
cs-fixer
leemyongpakvn Jul 6, 2022
6879f2d
Clearer warning
leemyongpakvn Jul 9, 2022
e1d47cb
Clearer function
leemyongpakvn Jul 19, 2022
d89b7d9
Clearer variable name
leemyongpakvn Jul 19, 2022
aefb99a
Update productcomments.php
leemyongpakvn Jul 19, 2022
880f512
Simpler positive number check
leemyongpakvn Sep 16, 2022
dd564ac
still need Validate::isUnsignedInt
leemyongpakvn Sep 16, 2022
daf2e66
Error not Confirmation
leemyongpakvn Sep 16, 2022
80e25bb
Module::displayConfirmation with close button
leemyongpakvn Sep 16, 2022
3da8061
Merge pull request #146 from leemyongpakvn/patch-5
kpodemski Sep 19, 2022
c0d29bb
Merge pull request #141 from leemyongpakvn/dev
kpodemski Oct 10, 2022
0718b6a
Merge pull request #142 from leemyongpakvn/patch-1
kpodemski Oct 29, 2022
0db170d
improved lastname anonymization
kpodemski Nov 18, 2022
64fc935
Merge pull request #149 from kpodemski/fix/30345
Hlavtox Dec 9, 2022
c765b98
Remove microdata from listings
micka-fdz Dec 9, 2022
7b8cd2e
Merge pull request #150 from micka-fdz/remove-listing-microdata
kpodemski Dec 12, 2022
52c3750
Delete logo.gif
Hlavtox Jan 17, 2023
6ce10f9
Merge pull request #152 from Hlavtox/removegif
Hlavtox Jan 18, 2023
cc35428
remove unneeded require_once
Feb 23, 2023
925de89
remove unneeded require_once
Feb 23, 2023
0c15e47
remove unneeded check for PS 1.6 and prior
leemyongpakvn Feb 23, 2023
ec414f2
remove unneeded check for PS 1.6 and prior
leemyongpakvn Feb 23, 2023
0f2105f
realign
leemyongpakvn Feb 23, 2023
4fb52c2
Clean Bootstrap grid markup
micka-fdz Mar 1, 2023
b2036ef
Add "Close" translation
micka-fdz Mar 1, 2023
928dd63
Remove useless aria-labels
micka-fdz Mar 1, 2023
ad631f7
Use shorthand of Smarty assign function
micka-fdz Mar 1, 2023
c228f9b
Adjust material-icons classes
micka-fdz Mar 2, 2023
21ac19e
Improve inputs accessibility
micka-fdz Mar 2, 2023
8429883
Remove Hn tags
micka-fdz Mar 2, 2023
92733a6
Merge pull request #154 from micka-fdz/template-improvements
Hlavtox Mar 2, 2023
a84f9fb
Merge pull request #153 from leemyongpakvn/remove-unneeded-code
Hlavtox Mar 2, 2023
37c8e20
Update productcomments.php
Hlavtox Mar 4, 2023
538abe2
Update config.xml
Hlavtox Mar 4, 2023
184f874
Merge pull request #155 from Hlavtox/503
Hlavtox Mar 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions ProductComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,28 @@ 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;
}
if ($n != null && $n <= 0) {
$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);
}

Expand Down Expand Up @@ -169,16 +170,16 @@ 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' : ''));
}

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
Expand All @@ -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' .
Expand Down Expand Up @@ -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);
}

Expand All @@ -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']);
Expand Down Expand Up @@ -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]);

Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down
16 changes: 8 additions & 8 deletions ProductCommentCriterion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . ')
');
}

Expand All @@ -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 . ')
');
}

Expand All @@ -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) . ')');
}
Expand All @@ -169,20 +169,20 @@ 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`
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 . ')
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
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>productcomments</name>
<displayName><![CDATA[Product Comments]]></displayName>
<version><![CDATA[5.0.2]]></version>
<version><![CDATA[5.0.3]]></version>
<description><![CDATA[Allows users to post reviews and rate products on specific criteria.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[front_office_features]]></tab>
Expand Down
36 changes: 27 additions & 9 deletions controllers/front/ListComments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand All @@ -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;
}
}
Binary file removed logo.gif
Binary file not shown.
Loading