Feat: Display ratings in footer

This commit is contained in:
Björn Fromme
2023-09-06 17:38:08 +02:00
parent 4b73bbe902
commit 89e45d573c
3 changed files with 54 additions and 0 deletions
@@ -0,0 +1,48 @@
<?php
namespace EP\EpTheme\DataProcessing;
use EP\EpProducts\Traits\DbConnectionTrait;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
class ProductRatingProcessor implements DataProcessorInterface
{
use DbConnectionTrait;
public function process(
ContentObjectRenderer $cObj,
array $contentObjectConfiguration,
array $processorConfiguration,
array $processedData
) {
$qb = $this->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;
}
}