Automattic\WooCommerce\Admin\API\Reports

GenericController::get_items()publicWC 1.0

Get the report data.

Prepares query params, fetches the report data from the data store, prepares it for the response, and packs it into the convention-conforming response object.

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

Хуков нет.

Возвращает

\WP_Error|\WP_REST_Response.

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

$GenericController = new GenericController();
$GenericController->get_items( $request );
$request(\WP_REST_Request) (обязательный)
Request data.

Код GenericController::get_items() WC 9.4.2

public function get_items( $request ) {
	$query_args  = $this->prepare_reports_query( $request );
	$report_data = $this->get_datastore_data( $query_args );

	if ( is_wp_error( $report_data ) ) {
		return $report_data;
	}

	if ( ! isset( $report_data->data ) || ! isset( $report_data->page_no ) || ! isset( $report_data->pages ) ) {
		return new \WP_Error( 'woocommerce_rest_reports_invalid_response', __( 'Invalid response from data store.', 'woocommerce' ), array( 'status' => 500 ) );
	}

	$out_data = array();

	foreach ( $report_data->data as $datum ) {
		$item       = $this->prepare_item_for_response( $datum, $request );
		$out_data[] = $this->prepare_response_for_collection( $item );
	}

	return $this->add_pagination_headers(
		$request,
		$out_data,
		(int) $report_data->total,
		(int) $report_data->page_no,
		(int) $report_data->pages
	);
}