| @@ -4,8 +4,9 @@ | ||
| 4 | 4 | |
| 5 | 5 | use FluentCart\Api\ModuleSettings; |
| 6 | 6 | use FluentCart\App\Helpers\Helper; |
| 7 | 7 | use FluentCart\App\Models\Product; |
| 8 | +use FluentCart\App\Services\ProductReviewService; | |
| 8 | 9 | use FluentCart\App\Modules\Templating\AssetLoader; |
| 9 | 10 | use FluentCart\Framework\Support\Arr; |
| 10 | 11 | |
| 11 | 12 | class ProductCardRender |
| @@ -156,8 +157,12 @@ | ||
| 156 | 157 | if ((new \FluentCart\Api\StoreSettings())->get($ratingVisibilitySettingKey, 'yes') !== 'yes') { |
| 157 | 158 | return; |
| 158 | 159 | } |
| 159 | 160 | |
| 161 | + if (!ProductReviewService::ratingMeetsThresholds($this->product, $this->config)) { | |
| 162 | + return; | |
| 163 | + } | |
| 164 | + | |
| 160 | 165 | $otherInfo = $this->product->detail->other_info ?: []; |
| 161 | 166 | $avgRating = Arr::get($otherInfo, 'average_rating', 0); |
| 162 | 167 | $reviewCount = (int) Arr::get($otherInfo, 'review_count', 0); |
| 163 | 168 | |
| @@ -175,15 +180,15 @@ | ||
| 175 | 180 | __('Rated %1$s out of 5 based on %2$d reviews', 'fluent-cart'), $avgRating, $reviewCount)); ?>"> |
| 176 | 181 | <span class="fct-product-card-stars" aria-hidden="true"> |
| 177 | 182 | <?php |
| 178 | 183 | for ($i = 0; $i < $fullStars; $i++) { |
| 179 | - echo '<span class="fct-star fct-star-filled">★</span>'; | |
| 184 | + echo '<span class="fct-star fct-star-filled">' . ReviewThreadMarkup::starSvg() . '</span>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 180 | 185 | } |
| 181 | 186 | if ($halfStar) { |
| 182 | - echo '<span class="fct-star fct-star-half"><span class="fct-star-half-empty">★</span><span class="fct-star-half-fill">★</span></span>'; | |
| 187 | + echo '<span class="fct-star fct-star-half"><span class="fct-star-half-empty">' . ReviewThreadMarkup::starSvg() . '</span><span class="fct-star-half-fill">' . ReviewThreadMarkup::starSvg() . '</span></span>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 183 | 188 | } |
| 184 | 189 | for ($i = 0; $i < $emptyStars; $i++) { |
| 185 | - echo '<span class="fct-star fct-star-empty">★</span>'; | |
| 190 | + echo '<span class="fct-star fct-star-empty">' . ReviewThreadMarkup::starSvg() . '</span>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 186 | 191 | } |
| 187 | 192 | ?> |
| 188 | 193 | </span> |
| 189 | 194 | <span class="fct-product-card-review-count">(<?php echo esc_html($reviewCount); ?>)</span> |
| @@ -190,10 +195,14 @@ | ||
| 190 | 195 | </div> |
| 191 | 196 | <?php |
| 192 | 197 | } |
| 193 | 198 | |
| 194 | - public function renderStarRatingBlock($wrapperAttributes = '') | |
| 199 | + public function renderStarRatingBlock($wrapperAttributes = '', array $attributes = [], $block = null) | |
| 195 | 200 | { |
| 201 | + if (!ProductReviewService::ratingMeetsThresholds($this->product, $attributes, $block)) { | |
| 202 | + return; | |
| 203 | + } | |
| 204 | + | |
| 196 | 205 | $otherInfo = $this->product->detail->other_info ?: []; |
| 197 | 206 | $avgRating = Arr::get($otherInfo, 'average_rating', 0); |
| 198 | 207 | $reviewCount = (int) Arr::get($otherInfo, 'review_count', 0); |
| 199 | 208 | |
| @@ -207,15 +216,15 @@ | ||
| 207 | 216 | __('Rated %1$s out of 5 based on %2$d reviews', 'fluent-cart'), $avgRating, $reviewCount)); ?>"> |
| 208 | 217 | <span class="fct-product-card-stars" aria-hidden="true"> |
| 209 | 218 | <?php |
| 210 | 219 | for ($i = 0; $i < $fullStars; $i++) { |
| 211 | - echo '<span class="fct-star fct-star-filled">★</span>'; | |
| 220 | + echo '<span class="fct-star fct-star-filled">' . ReviewThreadMarkup::starSvg() . '</span>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 212 | 221 | } |
| 213 | 222 | if ($halfStar) { |
| 214 | - echo '<span class="fct-star fct-star-half"><span class="fct-star-half-empty">★</span><span class="fct-star-half-fill">★</span></span>'; | |
| 223 | + echo '<span class="fct-star fct-star-half"><span class="fct-star-half-empty">' . ReviewThreadMarkup::starSvg() . '</span><span class="fct-star-half-fill">' . ReviewThreadMarkup::starSvg() . '</span></span>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 215 | 224 | } |
| 216 | 225 | for ($i = 0; $i < $emptyStars; $i++) { |
| 217 | - echo '<span class="fct-star fct-star-empty">★</span>'; | |
| 226 | + echo '<span class="fct-star fct-star-empty">' . ReviewThreadMarkup::starSvg() . '</span>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 218 | 227 | } |
| 219 | 228 | ?> |
| 220 | 229 | </span> |
| 221 | 230 | <span class="fct-product-card-review-count">(<?php echo esc_html($reviewCount); ?>)</span> |