PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.8.0
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.8.0
1.8.0 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 All 52 releases
← All changes | api/Resource/ProductReviewResource.php +48 -1 1.7.0 → 1.8.0 View file →
@@ -24,9 +24,10 @@
24 24 $query = static::getQuery();
25 25
26 26 $status = Arr::get($params, 'status', 'all');
27 27 $postId = Arr::get($params, 'post_id');
28 - $rating = Arr::get($params, 'rating');
28 + // A list of stars from the storefront's chips wins over a single rating.
29 + $rating = Arr::get($params, 'ratings') ?: Arr::get($params, 'rating');
29 30 $search = Arr::get($params, 'search');
30 31 $sortBy = Arr::get($params, 'sort_by', 'id');
31 32 $sortOrder = Arr::get($params, 'sort_order', 'DESC');
32 33 $perPage = min(100, max(1, (int) Arr::get($params, 'per_page', 15)));
@@ -51,8 +52,12 @@
51 52 if (Arr::get($params, 'verified_only')) {
52 53 $query->where('is_verified', 1);
53 54 }
54 55
56 + if (Arr::get($params, 'all_products')) {
57 + static::scopeToReviewableProducts($query, $params);
58 + }
59 +
55 60 // Allow extensions to apply advanced filters (e.g. saved views from Pro)
56 61 $filterType = Arr::get($params, 'filter_type', 'simple');
57 62 if ($filterType === 'advanced') {
58 63 $advancedFilters = Arr::get($params, 'advanced_filters', []);
@@ -106,8 +111,50 @@
106 111
107 112 // Null page falls through to the paginator's own request resolution,
108 113 // the same shape every sibling resource uses.
109 114 return $query->paginate($perPage, ['*'], 'page', Arr::get($params, 'page'));
115 + }
116 +
117 + /**
118 + * A store-wide list: reviews of published products that take reviews, narrowed
119 + * to the products and categories the caller named. Callers cap the id lists.
120 + *
121 + * @param Builder $query
122 + * @param array $params product_ids, category_ids
123 + * @return void
124 + */
125 + protected static function scopeToReviewableProducts($query, array $params)
126 + {
127 + $productIds = array_values(array_filter(array_map('intval', (array) Arr::get($params, 'product_ids', []))));
128 + $categoryIds = array_values(array_filter(array_map('intval', (array) Arr::get($params, 'category_ids', []))));
129 +
130 + // search() skips an empty value, so no product_ids means every product.
131 + $query->search([
132 + 'post_id' => ['operator' => 'in', 'value' => $productIds],
133 + ]);
134 +
135 + // Product's global scope already limits this to fluent-products.
136 + $query->whereHas('product', function ($productQuery) use ($categoryIds) {
137 + $productQuery->search([
138 + 'post_status' => ['operator' => '=', 'value' => 'publish'],
139 + ]);
140 +
141 + // The product's own reviews switch, the same flag
142 + // ProductReviewService::primeReviewsEnabled() reads. A missing detail
143 + // row or key counts as on.
144 + $productQuery->whereDoesntHave('detail', function ($detailQuery) {
145 + $detailQuery->reviewsDisabled();
146 + });
147 +
148 + if ($categoryIds) {
149 + $productQuery->whereHas('wpTerms', function ($termQuery) use ($categoryIds) {
150 + $termQuery->search([
151 + 'taxonomy' => ['operator' => '=', 'value' => 'product-categories'],
152 + 'term_id' => ['operator' => 'in', 'value' => $categoryIds],
153 + ]);
154 + });
155 + }
156 + });
110 157 }
111 158
112 159 public static function find($id, $params = [])
113 160 {