Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats

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 6.9.1

public function get_items( $request ) {
	$query_args    = $this->prepare_reports_query( $request );
	$coupons_query = new Query( $query_args );
	try {
		$report_data = $coupons_query->get_data();
	} catch ( ParameterException $e ) {
		return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
	}

	$out_data = array(
		'totals'    => get_object_vars( $report_data->totals ),
		'intervals' => array(),
	);

	foreach ( $report_data->intervals as $interval_data ) {
		$item                    = $this->prepare_item_for_response( (object) $interval_data, $request );
		$out_data['intervals'][] = $this->prepare_response_for_collection( $item );
	}

	$response = rest_ensure_response( $out_data );
	$response->header( 'X-WP-Total', (int) $report_data->total );
	$response->header( 'X-WP-TotalPages', (int) $report_data->pages );

	$page      = $report_data->page_no;
	$max_pages = $report_data->pages;
	$base      = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
	if ( $page > 1 ) {
		$prev_page = $page - 1;
		if ( $prev_page > $max_pages ) {
			$prev_page = $max_pages;
		}
		$prev_link = add_query_arg( 'page', $prev_page, $base );
		$response->link_header( 'prev', $prev_link );
	}
	if ( $max_pages > $page ) {
		$next_page = $page + 1;
		$next_link = add_query_arg( 'page', $next_page, $base );
		$response->link_header( 'next', $next_link );
	}

	return $response;
}