Automattic\WooCommerce\Admin

ReportCSVExporter::prepare_data_to_export()publicWC 1.0

Prepare data for export.

Метод класса: ReportCSVExporter{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$ReportCSVExporter = new ReportCSVExporter();
$ReportCSVExporter->prepare_data_to_export();

Код ReportCSVExporter::prepare_data_to_export() WC 8.7.0

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 );
}