Automattic\WooCommerce\Admin
ReportCSVExporter::prepare_data_to_export()
Prepare data for export.
Method of the class: ReportCSVExporter{}
No Hooks.
Return
null
. Nothing (null).
Usage
$ReportCSVExporter = new ReportCSVExporter(); $ReportCSVExporter->prepare_data_to_export();
ReportCSVExporter::prepare_data_to_export() ReportCSVExporter::prepare data to export code WC 9.2.3
public function prepare_data_to_export() { $request = new \WP_REST_Request( 'GET', "/wc-analytics/reports/{$this->report_type}" ); $params = $this->controller->get_collection_params(); $defaults = array(); foreach ( $params as $arg => $options ) { if ( isset( $options['default'] ) ) { $defaults[ $arg ] = $options['default']; } } $request->set_attributes( array( 'args' => $params ) ); $request->set_default_params( $defaults ); $request->set_query_params( $this->report_args ); $request->sanitize_params(); // Does the controller have an export-specific item retrieval method? // @todo - Potentially revisit. This is only for /revenue/stats/. if ( is_callable( array( $this->controller, 'get_export_items' ) ) ) { $response = $this->controller->get_export_items( $request ); } else { $response = $this->controller->get_items( $request ); } // Use WP_REST_Server::response_to_data() to embed links in data. add_filter( 'woocommerce_rest_check_permissions', '__return_true' ); $rest_server = rest_get_server(); $report_data = $rest_server->response_to_data( $response, true ); remove_filter( 'woocommerce_rest_check_permissions', '__return_true' ); $report_meta = $response->get_headers(); $this->total_rows = $report_meta['X-WP-Total']; $this->row_data = array_map( array( $this, 'generate_row_data' ), $report_data ); }