Clean tables when order is deleted

This commit is contained in:
Claudio Sanches 2019-02-05 16:15:39 -02:00
parent 10f40d4cf3
commit 86c3c00480
5 changed files with 26 additions and 0 deletions

View File

@ -511,6 +511,9 @@ class WC_Admin_Api_Init {
WC_Admin_Reports_Orders_Stats_Data_Store::init();
WC_Admin_Reports_Customers_Data_Store::init();
WC_Admin_Reports_Coupons_Data_Store::init();
WC_Admin_Reports_Products_Data_Store::init();
WC_Admin_Reports_Taxes_Data_Store::init();
}
/**

View File

@ -51,6 +51,13 @@ class WC_Admin_Reports_Coupons_Data_Store extends WC_Admin_Reports_Data_Store im
$this->report_columns['orders_count'] = str_replace( 'order_id', $table_name . '.order_id', $this->report_columns['orders_count'] );
}
/**
* Set up all the hooks for maintaining and populating table data.
*/
public static function init() {
add_action( 'woocommerce_reports_delete_order_stats', array( __CLASS__, 'sync_on_order_delete' ), 5 );
}
/**
* Returns comma separated ids of included coupons, based on query arguments from the user.
*

View File

@ -82,6 +82,13 @@ class WC_Admin_Reports_Products_Data_Store extends WC_Admin_Reports_Data_Store i
$this->report_columns['orders_count'] = str_replace( 'order_id', $table_name . '.order_id', $this->report_columns['orders_count'] );
}
/**
* Set up all the hooks for maintaining and populating table data.
*/
public static function init() {
add_action( 'woocommerce_reports_delete_order_stats', array( __CLASS__, 'sync_on_order_delete' ), 10 );
}
/**
* Fills ORDER BY clause of SQL request based on user supplied parameters.
*

View File

@ -66,6 +66,13 @@ class WC_Admin_Reports_Taxes_Data_Store extends WC_Admin_Reports_Data_Store impl
$this->report_columns['orders_count'] = str_replace( 'order_id', $table_name . '.order_id', $this->report_columns['orders_count'] );
}
/**
* Set up all the hooks for maintaining and populating table data.
*/
public static function init() {
add_action( 'woocommerce_reports_delete_order_stats', array( __CLASS__, 'sync_on_order_delete' ), 15 );
}
/**
* Updates the database query with parameters used for Taxes report: categories and order status.
*

View File

@ -3306,6 +3306,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
$order->apply_coupon( $coupon );
$order->save();
WC_Helper_Queue::run_all_pending();
// Check if lookup tables are populated.
foreach ( $tables as $table ) {
$results = $wpdb->get_results(