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

Controller::get_item_schema()publicWC 1.0

Get the Report's schema, conforming to JSON Schema.

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

Хуков нет.

Возвращает

Массив.

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

$Controller = new Controller();
$Controller->get_item_schema();

Код Controller::get_item_schema() WC 6.6.1

public function get_item_schema() {
	$data_values = array(
		'amount'        => array(
			'description' => __( 'Net discount amount.', 'woocommerce' ),
			'type'        => 'number',
			'context'     => array( 'view', 'edit' ),
			'readonly'    => true,
			'indicator'   => true,
			'format'      => 'currency',
		),
		'coupons_count' => array(
			'description' => __( 'Number of coupons.', 'woocommerce' ),
			'type'        => 'integer',
			'context'     => array( 'view', 'edit' ),
			'readonly'    => true,
		),
		'orders_count'  => array(
			'title'       => __( 'Discounted orders', 'woocommerce' ),
			'description' => __( 'Number of discounted orders.', 'woocommerce' ),
			'type'        => 'integer',
			'context'     => array( 'view', 'edit' ),
			'readonly'    => true,
			'indicator'   => true,
		),
	);

	$segments = array(
		'segments' => array(
			'description' => __( 'Reports data grouped by segment condition.', 'woocommerce' ),
			'type'        => 'array',
			'context'     => array( 'view', 'edit' ),
			'readonly'    => true,
			'items'       => array(
				'type'       => 'object',
				'properties' => array(
					'segment_id' => array(
						'description' => __( 'Segment identificator.', 'woocommerce' ),
						'type'        => 'integer',
						'context'     => array( 'view', 'edit' ),
						'readonly'    => true,
					),
					'subtotals'  => array(
						'description' => __( 'Interval subtotals.', 'woocommerce' ),
						'type'        => 'object',
						'context'     => array( 'view', 'edit' ),
						'readonly'    => true,
						'properties'  => $data_values,
					),
				),
			),
		),
	);

	$totals = array_merge( $data_values, $segments );

	$schema = array(
		'$schema'    => 'http://json-schema.org/draft-04/schema#',
		'title'      => 'report_coupons_stats',
		'type'       => 'object',
		'properties' => array(
			'totals'    => array(
				'description' => __( 'Totals data.', 'woocommerce' ),
				'type'        => 'object',
				'context'     => array( 'view', 'edit' ),
				'readonly'    => true,
				'properties'  => $totals,
			),
			'intervals' => array(
				'description' => __( 'Reports data grouped by intervals.', 'woocommerce' ),
				'type'        => 'array',
				'context'     => array( 'view', 'edit' ),
				'readonly'    => true,
				'items'       => array(
					'type'       => 'object',
					'properties' => array(
						'interval'       => array(
							'description' => __( 'Type of interval.', 'woocommerce' ),
							'type'        => 'string',
							'context'     => array( 'view', 'edit' ),
							'readonly'    => true,
							'enum'        => array( 'day', 'week', 'month', 'year' ),
						),
						'date_start'     => array(
							'description' => __( "The date the report start, in the site's timezone.", 'woocommerce' ),
							'type'        => 'date-time',
							'context'     => array( 'view', 'edit' ),
							'readonly'    => true,
						),
						'date_start_gmt' => array(
							'description' => __( 'The date the report start, as GMT.', 'woocommerce' ),
							'type'        => 'date-time',
							'context'     => array( 'view', 'edit' ),
							'readonly'    => true,
						),
						'date_end'       => array(
							'description' => __( "The date the report end, in the site's timezone.", 'woocommerce' ),
							'type'        => 'date-time',
							'context'     => array( 'view', 'edit' ),
							'readonly'    => true,
						),
						'date_end_gmt'   => array(
							'description' => __( 'The date the report end, as GMT.', 'woocommerce' ),
							'type'        => 'date-time',
							'context'     => array( 'view', 'edit' ),
							'readonly'    => true,
						),
						'subtotals'      => array(
							'description' => __( 'Interval subtotals.', 'woocommerce' ),
							'type'        => 'object',
							'context'     => array( 'view', 'edit' ),
							'readonly'    => true,
							'properties'  => $totals,
						),
					),
				),
			),
		),
	);

	return $this->add_additional_fields_schema( $schema );
}