PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.7.1
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.7.1
1.7.1 1.7.0 1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 All 51 releases
← All changes | app/Hooks/Handlers/BlockEditors/ProductRatingBlockEditor.php +13 -26 1.7.0 → 1.7.1 View file →
@@ -1,8 +1,9 @@
1 1 <?php
2 2
3 3 namespace FluentCart\App\Hooks\Handlers\BlockEditors;
4 4
5 +use FluentCart\Api\ModuleSettings;
5 6 use FluentCart\App\Services\Renderer\ProductCardRender;
6 7 use FluentCart\App\Services\Translations\TransStrings;
7 8 use FluentCart\Framework\Support\Arr;
8 9
@@ -12,8 +13,12 @@
12 13
13 14 public function supports(): array
14 15 {
15 16 return [
17 + // Out of the inserter while the reviews module is off; the block
18 + // is still registered so the card templates that carry it keep
19 + // parsing (see actions.php). Mirrored in the JS registration.
20 + 'inserter' => ModuleSettings::isActive('reviews'),
16 21 'html' => false,
17 22 'align' => ['left', 'center', 'right'],
18 23 'typography' => [
19 24 'fontSize' => true,
@@ -74,8 +79,10 @@
74 79 'slug' => $this->slugPrefix,
75 80 'name' => static::getEditorName(),
76 81 'title' => __('Product Rating', 'fluent-cart'),
77 82 'description' => __('Display the star rating for a product.', 'fluent-cart'),
83 + // The editor draws nothing while the module is off.
84 + 'reviews_active' => ModuleSettings::isActive('reviews'),
78 85 ],
79 86 'fluent_cart_block_translation' => TransStrings::blockStrings(),
80 87 ];
81 88 }
@@ -88,8 +95,13 @@
88 95 }
89 96
90 97 public function render(array $shortCodeAttribute, $block = null)
91 98 {
99 + // No reviews module, no rating — whatever template carries the block.
100 + if (!ModuleSettings::isActive('reviews')) {
101 + return '';
102 + }
103 +
92 104 // Store-level kill switch: Settings → Store Settings → Product Page
93 105 // → Product Rating. The block controls per-layout presence (it ships
94 106 // in the loop templates and editors remove it freely); these toggles
95 107 // turn ratings off store-wide without editing every page.
@@ -109,39 +121,14 @@
109 121 if (!$product) {
110 122 return '';
111 123 }
112 124
113 - // An average over one or two reviews says very little, and five empty
114 - // stars on a new product reads as a bad rating rather than as no
115 - // rating. This is where a store draws that line.
116 - //
117 - // Counted from detail->other_info, the canonical aggregate the
118 - // renderer itself displays — recounting the rows here could disagree
119 - // with the number printed beside the stars.
120 - $minReviewCount = max(0, (int) Arr::get($shortCodeAttribute, 'minReviewCount', 0));
121 -
122 - if ($minReviewCount > 0 && $this->reviewCount($product) < $minReviewCount) {
123 - return '';
124 - }
125 -
126 - // The second half of the same question: how good the rating has to be
127 - // before it is worth printing. A store showing ratings as a selling
128 - // point can keep the two-star ones off the shelf edge.
129 - //
130 - // Clamped to the five the stars can draw — a threshold above 5 would
131 - // hide every product, which is a setting no one means to choose.
132 - $minAverageRating = min(5.0, max(0.0, (float) Arr::get($shortCodeAttribute, 'minAverageRating', 0)));
133 -
134 - if ($minAverageRating > 0 && $this->averageRating($product) < $minAverageRating) {
135 - return '';
136 - }
137 -
138 125 $wrapper_attributes = get_block_wrapper_attributes([
139 126 'class' => 'fct-product-card-rating',
140 127 ]);
141 128
142 129 ob_start();
143 - (new ProductCardRender($product))->renderStarRatingBlock($wrapper_attributes);
130 + (new ProductCardRender($product))->renderStarRatingBlock($wrapper_attributes, $shortCodeAttribute, $block);
144 131 return ob_get_clean();
145 132 }
146 133
147 134 /**