registerArgument('product', Product::class, 'The product', true); } /** * @param array $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext * @return mixed */ public function render() { $product = $this->renderChildren(); if ($product === null) { $product = $this->arguments['product']; } $ratingAverage = $product->getRatingAverage(); $ratingVotesCount = $product->getRatingVotesCount(); $fullStars = floor($ratingAverage); $halfStar = ($ratingAverage - $fullStars) > 0; $ratingAverageLabel = number_format($ratingAverage, 1, ',', '.'); $content = ''; for ($i = 1; $i <= $fullStars; $i++) { $content .= ''; } if ($halfStar) { $content .= ''; } $content .= sprintf('%s Sterne (%d)', $ratingAverageLabel, $ratingVotesCount); return $content; } }