From 5f734dadf61e208fac73f4c55df58c960203db01 Mon Sep 17 00:00:00 2001 From: "J.F. Viguier" Date: Fri, 4 Jun 2021 15:53:01 +0200 Subject: [PATCH 1/5] Upgrade to 4 version : add hooks and conf --- upgrade/install-4.0.0.php | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 upgrade/install-4.0.0.php diff --git a/upgrade/install-4.0.0.php b/upgrade/install-4.0.0.php new file mode 100644 index 00000000..2cbdecf4 --- /dev/null +++ b/upgrade/install-4.0.0.php @@ -0,0 +1,44 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + */ +if (!defined('_PS_VERSION_')) { + exit; +} + +function upgrade_module_4_0_0($object) +{ + $res = true; + if (!Configuration::hasKey('PRODUCT_COMMENTS_COMMENTS_PER_PAGE')) { + $res &= (bool) Configuration::set('PRODUCT_COMMENTS_COMMENTS_PER_PAGE', 5); + } + if (!Configuration::hasKey('PRODUCT_COMMENTS_USEFULNESS')) { + $res &= (bool) Configuration::set('PRODUCT_COMMENTS_USEFULNESS', 1); + } + $res &= (bool) $object->unregisterHook('displayRightColumnProduct'); + $res &= (bool) $object->registerHook('displayProductAdditionalInfo'); + $res &= (bool) $object->registerHook('displayFooterProduct'); + + return $res; +} From 3e86e859e39fe11d7eccd4a35310acd480ee0ece Mon Sep 17 00:00:00 2001 From: "J.F. Viguier" Date: Fri, 4 Jun 2021 16:01:58 +0200 Subject: [PATCH 2/5] Add default value to commentsPerPage --- src/Repository/ProductCommentRepository.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Repository/ProductCommentRepository.php b/src/Repository/ProductCommentRepository.php index af95a95f..6d22958d 100644 --- a/src/Repository/ProductCommentRepository.php +++ b/src/Repository/ProductCommentRepository.php @@ -79,6 +79,9 @@ public function __construct( */ public function paginate($productId, $page, $commentsPerPage, $validatedOnly) { + if (empty($commentsPerPage)) { + $commentsPerPage = 5; + } /** @var QueryBuilder $qb */ $qb = $this->connection->createQueryBuilder(); $qb From b7c5594210a151ed056dac3e6754f2a385668e06 Mon Sep 17 00:00:00 2001 From: "J.F. Viguier" Date: Fri, 4 Jun 2021 16:16:36 +0200 Subject: [PATCH 3/5] add constant --- src/Repository/ProductCommentRepository.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Repository/ProductCommentRepository.php b/src/Repository/ProductCommentRepository.php index 6d22958d..dfdfd19b 100644 --- a/src/Repository/ProductCommentRepository.php +++ b/src/Repository/ProductCommentRepository.php @@ -51,6 +51,8 @@ class ProductCommentRepository */ private $commentsMinimalTime; + const DEFAULT_COMMENTS_PER_PAGE = 5; + /** * @param Connection $connection * @param string $databasePrefix @@ -80,7 +82,7 @@ public function __construct( public function paginate($productId, $page, $commentsPerPage, $validatedOnly) { if (empty($commentsPerPage)) { - $commentsPerPage = 5; + $commentsPerPage = self::DEFAULT_COMMENTS_PER_PAGE; } /** @var QueryBuilder $qb */ $qb = $this->connection->createQueryBuilder(); From cf0ba03fca2258c09f9abe495ff865d2621a018b Mon Sep 17 00:00:00 2001 From: "J.F. Viguier" Date: Mon, 7 Jun 2021 12:58:43 +0200 Subject: [PATCH 4/5] Configuration updateValue --- upgrade/install-4.0.0.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/upgrade/install-4.0.0.php b/upgrade/install-4.0.0.php index 2cbdecf4..96c99310 100644 --- a/upgrade/install-4.0.0.php +++ b/upgrade/install-4.0.0.php @@ -31,10 +31,10 @@ function upgrade_module_4_0_0($object) { $res = true; if (!Configuration::hasKey('PRODUCT_COMMENTS_COMMENTS_PER_PAGE')) { - $res &= (bool) Configuration::set('PRODUCT_COMMENTS_COMMENTS_PER_PAGE', 5); + $res &= (bool) Configuration::updateValue('PRODUCT_COMMENTS_COMMENTS_PER_PAGE', 5); } if (!Configuration::hasKey('PRODUCT_COMMENTS_USEFULNESS')) { - $res &= (bool) Configuration::set('PRODUCT_COMMENTS_USEFULNESS', 1); + $res &= (bool) Configuration::updateValue('PRODUCT_COMMENTS_USEFULNESS', 1); } $res &= (bool) $object->unregisterHook('displayRightColumnProduct'); $res &= (bool) $object->registerHook('displayProductAdditionalInfo'); From fb2386cf99be51349aa3245ca18c342119c7ff40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Viguier?= <16720275+jf-viguier@users.noreply.github.com> Date: Fri, 4 Jun 2021 18:37:28 +0200 Subject: [PATCH 5/5] got's cast Co-authored-by: GoT --- upgrade/install-4.0.0.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upgrade/install-4.0.0.php b/upgrade/install-4.0.0.php index 96c99310..5baedfb0 100644 --- a/upgrade/install-4.0.0.php +++ b/upgrade/install-4.0.0.php @@ -40,5 +40,5 @@ function upgrade_module_4_0_0($object) $res &= (bool) $object->registerHook('displayProductAdditionalInfo'); $res &= (bool) $object->registerHook('displayFooterProduct'); - return $res; + return (bool) $res; }