diff --git a/public/typo3conf/ext/ep_theme/Classes/DataProcessing/ProductRatingProcessor.php b/public/typo3conf/ext/ep_theme/Classes/DataProcessing/ProductRatingProcessor.php new file mode 100644 index 00000000..b356e940 --- /dev/null +++ b/public/typo3conf/ext/ep_theme/Classes/DataProcessing/ProductRatingProcessor.php @@ -0,0 +1,48 @@ +getDbConnection()->createQueryBuilder(); + + $result = $qb + ->selectLiteral('SUM(product.rating_votes_count) as totalCount', 'SUM(product.rating_average) as totalAverage') + ->from('tx_epproducts_domain_model_product', 'product') + ->execute() + ->fetchAssociative() + ; + + $totalCount = $result['totalCount']; + $totalAverage = $result['totalAverage']; + + $result = $qb + ->selectLiteral('COUNT(*) as ratedCount') + ->from('tx_epproducts_domain_model_product', 'product') + ->where($qb->expr()->gt('product.rating_average', 0)) + ->execute() + ->fetchAssociative() + ; + + $ratedCount = $result['ratedCount']; + + $processedData['totalRatings'] = [ + 'totalCount' => $totalCount, + 'totalAverage' => $totalAverage/$ratedCount, + ]; + + return $processedData; + } +} diff --git a/public/typo3conf/ext/ep_theme/Configuration/TypoScript/Page/Main.typoscript b/public/typo3conf/ext/ep_theme/Configuration/TypoScript/Page/Main.typoscript index c1ab9ca9..31e129aa 100644 --- a/public/typo3conf/ext/ep_theme/Configuration/TypoScript/Page/Main.typoscript +++ b/public/typo3conf/ext/ep_theme/Configuration/TypoScript/Page/Main.typoscript @@ -95,6 +95,7 @@ page { dataProcessing { 10 = EP\EpTheme\DataProcessing\ContextProcessor 20 = EP\EpTheme\DataProcessing\SliderProcessor + 25 = EP\EpTheme\DataProcessing\ProductRatingProcessor 30 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor 30 { table = tx_epproducts_domain_model_badge diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Footer.html b/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Footer.html index bc7f7a74..765eb32a 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Footer.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Footer.html @@ -32,6 +32,11 @@ + +