Automattic\WooCommerce\Admin
ReportCSVExporter::prepare_data_to_export
Prepare data for export.
Method of the class: ReportCSVExporter{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$ReportCSVExporter = new ReportCSVExporter(); $ReportCSVExporter->prepare_data_to_export();
ReportCSVExporter::prepare_data_to_export() ReportCSVExporter::prepare data to export code WC 10.6.2
public function prepare_data_to_export() {
/**
* Used to add/overwrite report data endpoint.
*
* @since x.x.x
*
* @param string $endpoint The report's data endpoint.
* @param string $type The report's type.
*
* @returns string The report's endpoint.
*/
$report_endpoint = apply_filters(
'woocommerce_export_report_data_endpoint',
"/wc-analytics/reports/{$this->report_type}",
$this->report_type
);
$request = new \WP_REST_Request( 'GET', $report_endpoint );
$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 );
}