| @@ -50,11 +50,29 @@ | ||
| 50 | 50 | // Attach the resolved variation_display_title to each variation (batched, |
| 51 | 51 | // no N+1) so the admin order product picker matches the order item display. |
| 52 | 52 | AttributeHelper::attachVariationDisplayTitles($products->getCollection()); |
| 53 | 53 | |
| 54 | + $collection = $products->getCollection(); | |
| 55 | + | |
| 54 | 56 | $products->setCollection( |
| 55 | - $products->getCollection()->transform(function ($product) { | |
| 56 | - return $product->setAppends(['view_url', 'edit_url']); | |
| 57 | + $collection->transform(function ($product) { | |
| 58 | + $product->setAppends(['view_url', 'edit_url']); | |
| 59 | + | |
| 60 | + // Source rating from canonical detail.other_info (maintained by recalculateProductRatings). | |
| 61 | + // Use array_key_exists to avoid overwriting valid data with fallback-to-zero. | |
| 62 | + if ($product->detail) { | |
| 63 | + $otherInfo = $product->detail->other_info ?? []; | |
| 64 | + | |
| 65 | + if (array_key_exists('average_rating', $otherInfo)) { | |
| 66 | + $product->avg_rating = (float) $otherInfo['average_rating']; | |
| 67 | + } | |
| 68 | + | |
| 69 | + if (array_key_exists('review_count', $otherInfo)) { | |
| 70 | + $product->reviews_count = (int) $otherInfo['review_count']; | |
| 71 | + } | |
| 72 | + } | |
| 73 | + | |
| 74 | + return $product; | |
| 57 | 75 | }) |
| 58 | 76 | ); |
| 59 | 77 | |
| 60 | 78 | $products = apply_filters('fluent_cart/products_list', $products); |