| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace FluentCart\App\Services\Report; |
| 4 | 4 | |
| 5 | 5 | use FluentCart\App\App; |
| 6 | +use FluentCart\Framework\Database\Query\Builder as Query; | |
| 6 | 7 | |
| 7 | 8 | class SourceReportService extends ReportService |
| 8 | 9 | { |
| 9 | 10 | public function getSourceReportData($params = []) |
| @@ -31,8 +32,29 @@ | ||
| 31 | 32 | ]) |
| 32 | 33 | ->orderByRaw('gross_sales DESC'); |
| 33 | 34 | |
| 34 | 35 | $query = $this->applyFilters($query, $params); |
| 36 | + | |
| 37 | + /** | |
| 38 | + * Let listeners narrow the Order Sources report query. | |
| 39 | + * | |
| 40 | + * The free plugin only forwards the request params ('filter_type' and the | |
| 41 | + * raw 'advanced_filters' JSON among them) — it never parses or applies the | |
| 42 | + * advanced filters itself. FluentCart Pro owns that: it reads the params, | |
| 43 | + * builds the condition groups through the Orders filter engine and adds | |
| 44 | + * the constraints to this query. | |
| 45 | + * | |
| 46 | + * @param \FluentCart\Framework\Database\Query\Builder $query | |
| 47 | + * @param array $params Processed report params. | |
| 48 | + */ | |
| 49 | + $filteredQuery = apply_filters('fluent_cart/report/sources_query', $query, $params); | |
| 50 | + | |
| 51 | + // A callback that returns something other than a query builder (null, | |
| 52 | + // an array, a thrown-away clone of the wrong type) would fatal the whole | |
| 53 | + // report, so fall back to the unmodified query instead. | |
| 54 | + if ($filteredQuery instanceof Query) { | |
| 55 | + $query = $filteredQuery; | |
| 56 | + } | |
| 35 | 57 | |
| 36 | 58 | return $query->get(); |
| 37 | 59 | } |
| 38 | 60 | |