Automattic\WooCommerce\Admin\API\Reports\Categories

Controller::get_items()publicWC 1.0

Get all reports.

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

Хуков нет.

Возвращает

Массив|WP_Error.

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

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

Код Controller::get_items() WC 8.6.1

public function get_items( $request ) {
	$query_args       = $this->prepare_reports_query( $request );
	$categories_query = new Query( $query_args );
	$report_data      = $categories_query->get_data();

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