diff --git a/productcomments.php b/productcomments.php index a786e643..591f5808 100644 --- a/productcomments.php +++ b/productcomments.php @@ -86,7 +86,7 @@ public function install($keep = true) !$this->registerHook('header') || //Adds css and javascript on front !$this->registerHook('displayProductListReviews') || //Product list miniature !$this->registerHook('displayProductAdditionalInfo') || //Display info in checkout column - + !$this->registerHook('filterProductContent') || // Add infos to Product page !$this->registerHook('registerGDPRConsent') || !$this->registerHook('actionDeleteGDPRCustomer') || !$this->registerHook('actionExportGDPRData') || @@ -896,6 +896,29 @@ public function hookDisplayFooterProduct($params) return $this->renderProductCommentsList($params['product']) . $this->renderProductCommentModal($params['product']); } + /** + * Inject data about productcomments in the product object for frontoffice + * + * @param array $params + * @return void + */ + public function hookFilterProductContent(array $params): void + { + if (empty($params['object']->id)) { + return; + } + /** @var ProductCommentRepository $productCommentRepository */ + $productCommentRepository = $this->context->controller->getContainer()->get('product_comment_repository'); + + $averageRating = $productCommentRepository->getAverageGrade($params['object']->id, (bool) Configuration::get('PRODUCT_COMMENTS_MODERATE')); + $commentsNb = $productCommentRepository->getCommentsNumber($params['object']->id, (bool) Configuration::get('PRODUCT_COMMENTS_MODERATE')); + + $params['object']->productComments = [ + 'averageRating' => $averageRating, + 'numComments' => $commentsNb, + ]; + } + /** * Used to render the product comments list * diff --git a/upgrade/install-4.2.3.php b/upgrade/install-4.2.3.php new file mode 100644 index 00000000..808dce5f --- /dev/null +++ b/upgrade/install-4.2.3.php @@ -0,0 +1,33 @@ + + * @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_2_3($object) +{ + return $object->registerHook('filterProductContent'); +}