@@ -20,38 +20,63 @@ class DataStoreModifier implements Hookable {
2020 */
2121 public function register_hooks (): void {
2222 add_filter ( 'woocommerce_data_stores ' , [ $ this , 'modify_wc_products_stats_datastore ' ], 20 );
23+ add_filter ( 'woocommerce_rest_reports_column_types ' , [ $ this , 'add_dokan_column_types ' ], 10 , 1 );
2324 }
2425
2526 /**
26- * Customize the WooCommerce products stats datastore to override the $total_query and $interval_query properties.
27- * This modification replaces the Automattic\WooCommerce\Admin\API\Reports\SqlQuery class with WeDevs\Dokan\Analytics\Reports\WcSqlQuery
28- * to apply specific filters to queries.
29- * The reason for this change is that the "get_sql_clause" method's second parameter defaults to "unfiltered," which blocks the filters we need
30- * to add JOIN and WHERE clauses for the dokan_order_stats table.
27+ * Add Dokan column types to the WooCommerce reports.
3128 *
32- * @see https://github.com/woocommerce/woocommerce/blob/9297409c5a705d1cd0ae65ec9b058271bd90851e/plugins/woocommerce/src/Admin/API/Reports/Products/Stats/DataStore.php#L170
29+ * @since 4.2.8
3330 *
34- * @param array $wc_stores An array of WooCommerce datastores.
35- * @return array Modified array of WooCommerce datastores.
31+ * @param array $column_types
32+ * @return array
3633 */
34+ public function add_dokan_column_types ( $ column_types ) {
35+ $ dokan_column_types = [
36+ 'avg_admin_commission ' => 'floatval ' ,
37+ 'avg_vendor_earning ' => 'floatval ' ,
38+ 'total_admin_commission ' => 'floatval ' ,
39+ 'total_vendor_earning ' => 'floatval ' ,
40+ 'total_vendor_gateway_fee ' => 'floatval ' ,
41+ 'total_vendor_discount ' => 'floatval ' ,
42+ 'total_admin_gateway_fee ' => 'floatval ' ,
43+ 'total_admin_discount ' => 'floatval ' ,
44+ 'total_admin_subsidy ' => 'floatval ' ,
45+ ];
46+
47+ return array_merge ( $ column_types , $ dokan_column_types );
48+ }
49+
50+ /**
51+ * Customize the WooCommerce products stats datastore to override the $total_query and $interval_query properties.
52+ * This modification replaces the Automattic\WooCommerce\Admin\API\Reports\SqlQuery class with WeDevs\Dokan\Analytics\Reports\WcSqlQuery
53+ * to apply specific filters to queries.
54+ * The reason for this change is that the "get_sql_clause" method's second parameter defaults to "unfiltered," which blocks the filters we need
55+ * to add JOIN and WHERE clauses for the dokan_order_stats table.
56+ *
57+ * @see https://github.com/woocommerce/woocommerce/blob/9297409c5a705d1cd0ae65ec9b058271bd90851e/plugins/woocommerce/src/Admin/API/Reports/Products/Stats/DataStore.php#L170
58+ *
59+ * @param array $wc_stores An array of WooCommerce datastores.
60+ * @return array Modified array of WooCommerce datastores.
61+ */
3762 public function modify_wc_products_stats_datastore ( $ wc_stores ) {
3863 if ( isset ( $ wc_stores ['report-products-stats ' ] ) ) {
3964 $ wc_stores ['report-products-stats ' ] = \WeDevs \Dokan \Analytics \Reports \Products \Stats \WcDataStore::class;
4065 }
4166
42- if ( isset ( $ wc_stores ['report-taxes-stats ' ] ) ) {
67+ if ( isset ( $ wc_stores ['report-taxes-stats ' ] ) ) {
4368 $ wc_stores ['report-taxes-stats ' ] = \WeDevs \Dokan \Analytics \Reports \Taxes \Stats \WcDataStore::class;
4469 }
4570
46- if ( isset ( $ wc_stores ['report-orders-stats ' ] ) ) {
71+ if ( isset ( $ wc_stores ['report-orders-stats ' ] ) ) {
4772 $ wc_stores ['report-orders-stats ' ] = \WeDevs \Dokan \Analytics \Reports \Orders \Stats \WcDataStore::class;
4873 }
4974
50- if ( isset ( $ wc_stores ['report-coupons-stats ' ] ) ) {
75+ if ( isset ( $ wc_stores ['report-coupons-stats ' ] ) ) {
5176 $ wc_stores ['report-coupons-stats ' ] = \WeDevs \Dokan \Analytics \Reports \Coupons \Stats \WcDataStore::class;
5277 }
5378
54- if ( isset ( $ wc_stores ['report-stock-stats ' ] ) ) {
79+ if ( isset ( $ wc_stores ['report-stock-stats ' ] ) ) {
5580 $ wc_stores ['report-stock-stats ' ] = \WeDevs \Dokan \Analytics \Reports \Stock \Stats \WcDataStore::class;
5681 }
5782
0 commit comments