Feat: Display ratings in footer
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user