- Removed duplicate class.
- Overridden REST API endpoints via filters. - Updated data store class prefixes. - Removed debugging echo.
This commit is contained in:
parent
9ac635fd42
commit
b556d55ca6
|
@ -59,7 +59,7 @@ class WC_Admin_REST_Reports_Categories_Controller extends WC_REST_Reports_Contro
|
|||
*/
|
||||
public function get_items( $request ) {
|
||||
$query_args = $this->prepare_reports_query( $request );
|
||||
$categories_query = new WC_Reports_Categories_Query( $query_args );
|
||||
$categories_query = new WC_Admin_Reports_Categories_Query( $query_args );
|
||||
$report_data = $categories_query->get_data();
|
||||
|
||||
if ( is_wp_error( $report_data ) ) {
|
||||
|
|
|
@ -47,7 +47,7 @@ class WC_Admin_REST_Reports_Products_Controller extends WC_REST_Reports_Controll
|
|||
}
|
||||
}
|
||||
|
||||
$reports = new WC_Reports_Products_Query( $args );
|
||||
$reports = new WC_Admin_Reports_Products_Query( $args );
|
||||
$products_data = $reports->get_data();
|
||||
|
||||
$data = array();
|
||||
|
|
|
@ -53,7 +53,7 @@ class WC_Admin_REST_Reports_Products_Stats_Controller extends WC_REST_Reports_Co
|
|||
}
|
||||
}
|
||||
|
||||
$query = new WC_Reports_Products_Stats_Query( $query_args );
|
||||
$query = new WC_Admin_Reports_Products_Stats_Query( $query_args );
|
||||
$report_data = $query->get_data();
|
||||
|
||||
$out_data = array(
|
||||
|
|
|
@ -58,7 +58,7 @@ class WC_Admin_REST_Reports_Revenue_Stats_Controller extends WC_REST_Reports_Con
|
|||
*/
|
||||
public function get_items( $request ) {
|
||||
$query_args = $this->prepare_reports_query( $request );
|
||||
$reports_revenue = new WC_Reports_Revenue_Query( $query_args );
|
||||
$reports_revenue = new WC_Admin_Reports_Revenue_Query( $query_args );
|
||||
$report_data = $reports_revenue->get_data();
|
||||
|
||||
$out_data = array(
|
||||
|
|
|
@ -12,6 +12,8 @@ class WC_Admin_Api_Init {
|
|||
add_filter( 'woocommerce_install_get_tables', array( 'WC_Admin_Api_Init', 'add_report_tables' ) );
|
||||
// REST API extensions init.
|
||||
add_action( 'rest_api_init', array( $this, 'rest_api_init' ) );
|
||||
add_filter( 'rest_endpoints', array( 'WC_Admin_Api_Init', 'filter_rest_endpoints' ), 10, 1 );
|
||||
add_filter( 'woocommerce_debug_tools', array( 'WC_Admin_Api_Init', 'add_regenerate_tool' ) );
|
||||
// Initialize report classes.
|
||||
add_action( 'woocommerce_after_register_post_type', array( 'WC_Admin_Api_Init', 'orders_data_store_init' ), 20 );
|
||||
add_action( 'woocommerce_after_register_post_type', array( 'WC_Admin_Api_Init', 'order_product_lookup_store_init' ), 20 );
|
||||
|
@ -23,9 +25,10 @@ class WC_Admin_Api_Init {
|
|||
public function init_classes() {
|
||||
// Interfaces.
|
||||
require_once dirname( __FILE__ ) . '/interfaces/class-wc-admin-reports-data-store-interface.php';
|
||||
require_once dirname( __FILE__ ) . '/interfaces/class-wc-reports-data-store-interface.php';
|
||||
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-query.php';
|
||||
|
||||
// Common date time code.
|
||||
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-interval.php';
|
||||
|
||||
// Query classes for reports.
|
||||
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-revenue-query.php';
|
||||
|
@ -75,6 +78,52 @@ class WC_Admin_Api_Init {
|
|||
}
|
||||
}
|
||||
|
||||
public static function filter_rest_endpoints( $endpoints ) {
|
||||
// Override GET /wc/v3/system_status/tools.
|
||||
if ( isset( $endpoints['/wc/v3/system_status/tools'] )
|
||||
&& isset( $endpoints['/wc/v3/system_status/tools'][1] )
|
||||
&& isset( $endpoints['/wc/v3/system_status/tools'][0] )
|
||||
&& $endpoints['/wc/v3/system_status/tools'][1]['callback'][0] instanceof WC_Admin_REST_System_Status_Tools_Controller
|
||||
) {
|
||||
$endpoints['/wc/v3/system_status/tools'][0] = $endpoints['/wc/v3/system_status/tools'][1];
|
||||
}
|
||||
// // Override GET & PUT for /wc/v3/system_status/tools.
|
||||
if ( isset( $endpoints['/wc/v3/system_status/tools/(?P<id>[\w-]+)'] )
|
||||
&& isset( $endpoints['/wc/v3/system_status/tools/(?P<id>[\w-]+)'][3] )
|
||||
&& isset( $endpoints['/wc/v3/system_status/tools/(?P<id>[\w-]+)'][2] )
|
||||
&& $endpoints['/wc/v3/system_status/tools/(?P<id>[\w-]+)'][2]['callback'][0] instanceof WC_Admin_REST_System_Status_Tools_Controller
|
||||
&& $endpoints['/wc/v3/system_status/tools/(?P<id>[\w-]+)'][3]['callback'][0] instanceof WC_Admin_REST_System_Status_Tools_Controller
|
||||
) {
|
||||
$endpoints['/wc/v3/system_status/tools/(?P<id>[\w-]+)'][0] = $endpoints['/wc/v3/system_status/tools/(?P<id>[\w-]+)'][2];
|
||||
$endpoints['/wc/v3/system_status/tools/(?P<id>[\w-]+)'][1] = $endpoints['/wc/v3/system_status/tools/(?P<id>[\w-]+)'][3];
|
||||
}
|
||||
|
||||
// Override GET /wc/v3/reports.
|
||||
if ( isset( $endpoints['/wc/v3/reports'] )
|
||||
&& isset( $endpoints['/wc/v3/reports'][1] )
|
||||
&& isset( $endpoints['/wc/v3/reports'][0] )
|
||||
&& $endpoints['/wc/v3/reports'][1]['callback'][0] instanceof WC_Admin_REST_Reports_Controller
|
||||
) {
|
||||
$endpoints['/wc/v3/reports'][0] = $endpoints['/wc/v3/reports'][1];
|
||||
}
|
||||
|
||||
return $endpoints;
|
||||
}
|
||||
|
||||
public static function add_regenerate_tool( $tools ) {
|
||||
return array_merge(
|
||||
$tools,
|
||||
array(
|
||||
'rebuild_stats' => array(
|
||||
'name' => __( 'Rebuild reports data', 'woocommerce' ),
|
||||
'button' => __( 'Rebuild reports', 'woocommerce' ),
|
||||
'desc' => __( 'This tool will rebuild all of the information used by the reports.', 'woocommerce' ),
|
||||
'callback' => array( 'WC_Admin_Reports_Orders_Data_Store', 'queue_order_stats_repopulate_database' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static function orders_data_store_init() {
|
||||
WC_Admin_Reports_Orders_Data_Store::init();
|
||||
}
|
||||
|
@ -134,11 +183,11 @@ class WC_Admin_Api_Init {
|
|||
return array_merge(
|
||||
$data_stores,
|
||||
array(
|
||||
'report-revenue-stats' => 'WC_Reports_Orders_Data_Store',
|
||||
'report-orders-stats' => 'WC_Reports_Orders_Data_Store',
|
||||
'report-products' => 'WC_Reports_Products_Data_Store',
|
||||
'report-products-stats' => 'WC_Reports_Products_Stats_Data_Store',
|
||||
'report-categories' => 'WC_Reports_Categories_Data_Store',
|
||||
'report-revenue-stats' => 'WC_Admin_Reports_Orders_Data_Store',
|
||||
'report-orders-stats' => 'WC_Admin_Reports_Orders_Data_Store',
|
||||
'report-products' => 'WC_Admin_Reports_Products_Data_Store',
|
||||
'report-products-stats' => 'WC_Admin_Reports_Products_Stats_Data_Store',
|
||||
'report-categories' => 'WC_Admin_Reports_Categories_Data_Store',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* WC_Reports_Products_Query
|
||||
* WC_Admin_Reports_Products_Query
|
||||
*
|
||||
*/
|
||||
class WC_Admin_Reports_Products_Query extends WC_Admin_Reports_Query {
|
||||
|
|
|
@ -320,8 +320,6 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp
|
|||
{$intervals_query['limit']}", ARRAY_A
|
||||
); // WPCS: cache ok, DB call ok, unprepared SQL ok.
|
||||
|
||||
echo $wpdb->last_query;
|
||||
|
||||
if ( null === $intervals ) {
|
||||
return new WP_Error( 'woocommerce_reports_revenue_result_failed', __( 'Sorry, fetching revenue data failed.', 'woocommerce' ) );
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Reports Data Store Interface
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @package WooCommerce/Interface
|
||||
* @package WooCommerce Admin/Interface
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -15,7 +15,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
*
|
||||
* @since 3.5.0
|
||||
*/
|
||||
interface WC_Reports_Data_Store_Interface {
|
||||
interface WC_Admin_Reports_Data_Store_Interface {
|
||||
|
||||
/**
|
||||
* Get the data based on args.
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Reports Data Store Interface
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @package WooCommerce/Interface
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* WooCommerce Reports data store interface.
|
||||
*
|
||||
*/
|
||||
interface WC_Admin_Reports_Data_Store_Interface {
|
||||
|
||||
/**
|
||||
* Get the data based on args.
|
||||
*
|
||||
* @param array $args Query parameters.
|
||||
* @return stdClass|WP_Error
|
||||
*/
|
||||
public function get_data( $args );
|
||||
}
|
Loading…
Reference in New Issue