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;
}
}
@@ -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
@@ -32,6 +32,11 @@
</f:for>
</f:if>
</div>
<div class="container py-4 text-white text-xl border-t border-white">
{totalRatings.totalAverage -> f:format.number(decimalSeparator: ',')} Sterne bei {totalRatings.totalCount} Bewertungen
</div>
<div class="hidden md:block container{f:if(condition: settings.footerNavPid, then: ' border-t border-white pt-4')}">
<div class="grid grid-cols-2 gap-16">
<div class="flex">