Removed old reports
This commit is contained in:
parent
b472fb660f
commit
28b0d9c331
|
@ -34,5 +34,10 @@
|
|||
|
||||
## Removed endpoints
|
||||
|
||||
- Removed `reports/top_sellers` endpoint.
|
||||
- Removed `reports/sales` endpoint.
|
||||
- `reports/top_sellers`
|
||||
- `reports/sales`
|
||||
- `reports/customers/totals`
|
||||
- `reports/orders/totals`
|
||||
- `reports/coupons/totals`
|
||||
- `reports/reviews/totals`
|
||||
- `reports/products/totals`
|
||||
|
|
|
@ -1,143 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* REST API Reports Coupons Totals controller
|
||||
*
|
||||
* Handles requests to the /reports/coupons/count endpoint.
|
||||
*
|
||||
* @package WooCommerce/RestApi
|
||||
* @since 3.5.0
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Reports Coupons Totals controller class.
|
||||
*
|
||||
* @package WooCommerce/RestApi
|
||||
* @extends WC_REST_Reports_Controller
|
||||
*/
|
||||
class WC_REST_Report_Coupons_Totals_Controller extends WC_REST_Reports_Controller {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'wc/v3';
|
||||
|
||||
/**
|
||||
* Route base.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rest_base = 'reports/coupons/totals';
|
||||
|
||||
/**
|
||||
* Get reports list.
|
||||
*
|
||||
* @since 3.5.0
|
||||
* @return array
|
||||
*/
|
||||
protected function get_reports() {
|
||||
global $wpdb;
|
||||
|
||||
$data = get_transient( 'rest_api_coupons_type_count' );
|
||||
if ( false !== $data ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$types = wc_get_coupon_types();
|
||||
$data = array();
|
||||
|
||||
foreach ( $types as $slug => $name ) {
|
||||
$results = $wpdb->get_results(
|
||||
$wpdb->prepare( "
|
||||
SELECT count(meta_id) AS total
|
||||
FROM $wpdb->postmeta
|
||||
WHERE meta_key = 'discount_type'
|
||||
AND meta_value = %s
|
||||
", $slug )
|
||||
);
|
||||
|
||||
$total = isset( $results[0] ) ? (int) $results[0]->total : 0;
|
||||
|
||||
$data[] = array(
|
||||
'slug' => $slug,
|
||||
'name' => $name,
|
||||
'total' => $total,
|
||||
);
|
||||
}
|
||||
|
||||
set_transient( 'rest_api_coupons_type_count', $data, YEAR_IN_SECONDS );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a report object for serialization.
|
||||
*
|
||||
* @param stdClass $report Report data.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response $response Response data.
|
||||
*/
|
||||
public function prepare_item_for_response( $report, $request ) {
|
||||
$data = array(
|
||||
'slug' => $report->slug,
|
||||
'name' => $report->name,
|
||||
'total' => $report->total,
|
||||
);
|
||||
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
|
||||
// Wrap the data in a response object.
|
||||
$response = rest_ensure_response( $data );
|
||||
|
||||
/**
|
||||
* Filter a report returned from the API.
|
||||
*
|
||||
* Allows modification of the report data right before it is returned.
|
||||
*
|
||||
* @param WP_REST_Response $response The response object.
|
||||
* @param object $report The original report object.
|
||||
* @param WP_REST_Request $request Request used to generate the response.
|
||||
*/
|
||||
return apply_filters( 'woocommerce_rest_prepare_report_coupons_count', $response, $report, $request );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Report's schema, conforming to JSON Schema.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_item_schema() {
|
||||
$schema = array(
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'report_coupon_total',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'slug' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __( 'Coupon type name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'total' => array(
|
||||
'description' => __( 'Amount of coupons.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $this->add_additional_fields_schema( $schema );
|
||||
}
|
||||
}
|
|
@ -1,154 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* REST API Reports Customers Totals controller
|
||||
*
|
||||
* Handles requests to the /reports/customers/count endpoint.
|
||||
*
|
||||
* @package WooCommerce/RestApi
|
||||
* @since 3.5.0
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Reports Customers Totals controller class.
|
||||
*
|
||||
* @package WooCommerce/RestApi
|
||||
* @extends WC_REST_Reports_Controller
|
||||
*/
|
||||
class WC_REST_Report_Customers_Totals_Controller extends WC_REST_Reports_Controller {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'wc/v3';
|
||||
|
||||
/**
|
||||
* Route base.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rest_base = 'reports/customers/totals';
|
||||
|
||||
/**
|
||||
* Get reports list.
|
||||
*
|
||||
* @since 3.5.0
|
||||
* @return array
|
||||
*/
|
||||
protected function get_reports() {
|
||||
$users_count = count_users();
|
||||
$total_customers = 0;
|
||||
|
||||
foreach ( $users_count['avail_roles'] as $role => $total ) {
|
||||
if ( in_array( $role, array( 'administrator', 'shop_manager' ), true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$total_customers += (int) $total;
|
||||
}
|
||||
|
||||
$customers_query = new WP_User_Query(
|
||||
array(
|
||||
'role__not_in' => array( 'administrator', 'shop_manager' ),
|
||||
'number' => 0,
|
||||
'fields' => 'ID',
|
||||
'count_total' => true,
|
||||
'meta_query' => array( // WPCS: slow query ok.
|
||||
array(
|
||||
'key' => 'paying_customer',
|
||||
'value' => 1,
|
||||
'compare' => '=',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$total_paying = (int) $customers_query->get_total();
|
||||
|
||||
$data = array(
|
||||
array(
|
||||
'slug' => 'paying',
|
||||
'name' => __( 'Paying customer', 'woocommerce' ),
|
||||
'total' => $total_paying,
|
||||
),
|
||||
array(
|
||||
'slug' => 'non_paying',
|
||||
'name' => __( 'Non-paying customer', 'woocommerce' ),
|
||||
'total' => $total_customers - $total_paying,
|
||||
),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a report object for serialization.
|
||||
*
|
||||
* @param stdClass $report Report data.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response $response Response data.
|
||||
*/
|
||||
public function prepare_item_for_response( $report, $request ) {
|
||||
$data = array(
|
||||
'slug' => $report->slug,
|
||||
'name' => $report->name,
|
||||
'total' => $report->total,
|
||||
);
|
||||
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
|
||||
// Wrap the data in a response object.
|
||||
$response = rest_ensure_response( $data );
|
||||
|
||||
/**
|
||||
* Filter a report returned from the API.
|
||||
*
|
||||
* Allows modification of the report data right before it is returned.
|
||||
*
|
||||
* @param WP_REST_Response $response The response object.
|
||||
* @param object $report The original report object.
|
||||
* @param WP_REST_Request $request Request used to generate the response.
|
||||
*/
|
||||
return apply_filters( 'woocommerce_rest_prepare_report_customers_count', $response, $report, $request );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Report's schema, conforming to JSON Schema.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_item_schema() {
|
||||
$schema = array(
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'report_customer_total',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'slug' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __( 'Customer type name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'total' => array(
|
||||
'description' => __( 'Amount of customers.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $this->add_additional_fields_schema( $schema );
|
||||
}
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* REST API Reports Orders Totals controller
|
||||
*
|
||||
* Handles requests to the /reports/orders/count endpoint.
|
||||
*
|
||||
* @package WooCommerce/RestApi
|
||||
* @since 3.5.0
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Reports Orders Totals controller class.
|
||||
*
|
||||
* @package WooCommerce/RestApi
|
||||
* @extends WC_REST_Reports_Controller
|
||||
*/
|
||||
class WC_REST_Report_Orders_Totals_Controller extends WC_REST_Reports_Controller {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'wc/v3';
|
||||
|
||||
/**
|
||||
* Route base.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rest_base = 'reports/orders/totals';
|
||||
|
||||
/**
|
||||
* Get reports list.
|
||||
*
|
||||
* @since 3.5.0
|
||||
* @return array
|
||||
*/
|
||||
protected function get_reports() {
|
||||
$totals = wp_count_posts( 'shop_order' );
|
||||
$data = array();
|
||||
|
||||
foreach ( wc_get_order_statuses() as $slug => $name ) {
|
||||
if ( ! isset( $totals->$slug ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
'slug' => str_replace( 'wc-', '', $slug ),
|
||||
'name' => $name,
|
||||
'total' => (int) $totals->$slug,
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a report object for serialization.
|
||||
*
|
||||
* @param stdClass $report Report data.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response $response Response data.
|
||||
*/
|
||||
public function prepare_item_for_response( $report, $request ) {
|
||||
$data = array(
|
||||
'slug' => $report->slug,
|
||||
'name' => $report->name,
|
||||
'total' => $report->total,
|
||||
);
|
||||
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
|
||||
// Wrap the data in a response object.
|
||||
$response = rest_ensure_response( $data );
|
||||
|
||||
/**
|
||||
* Filter a report returned from the API.
|
||||
*
|
||||
* Allows modification of the report data right before it is returned.
|
||||
*
|
||||
* @param WP_REST_Response $response The response object.
|
||||
* @param object $report The original report object.
|
||||
* @param WP_REST_Request $request Request used to generate the response.
|
||||
*/
|
||||
return apply_filters( 'woocommerce_rest_prepare_report_orders_count', $response, $report, $request );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Report's schema, conforming to JSON Schema.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_item_schema() {
|
||||
$schema = array(
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'report_order_total',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'slug' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __( 'Order status name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'total' => array(
|
||||
'description' => __( 'Amount of orders.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $this->add_additional_fields_schema( $schema );
|
||||
}
|
||||
}
|
|
@ -1,133 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* REST API Reports Products Totals controller
|
||||
*
|
||||
* Handles requests to the /reports/products/count endpoint.
|
||||
*
|
||||
* @package WooCommerce/RestApi
|
||||
* @since 3.5.0
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Reports Products Totals controller class.
|
||||
*
|
||||
* @package WooCommerce/RestApi
|
||||
* @extends WC_REST_Reports_Controller
|
||||
*/
|
||||
class WC_REST_Report_Products_Totals_Controller extends WC_REST_Reports_Controller {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'wc/v3';
|
||||
|
||||
/**
|
||||
* Route base.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rest_base = 'reports/products/totals';
|
||||
|
||||
/**
|
||||
* Get reports list.
|
||||
*
|
||||
* @since 3.5.0
|
||||
* @return array
|
||||
*/
|
||||
protected function get_reports() {
|
||||
$types = wc_get_product_types();
|
||||
$terms = get_terms(
|
||||
array(
|
||||
'taxonomy' => 'product_type',
|
||||
'hide_empty' => false,
|
||||
)
|
||||
);
|
||||
$data = array();
|
||||
|
||||
foreach ( $terms as $product_type ) {
|
||||
if ( ! isset( $types[ $product_type->name ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
'slug' => $product_type->name,
|
||||
'name' => $types[ $product_type->name ],
|
||||
'total' => (int) $product_type->count,
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a report object for serialization.
|
||||
*
|
||||
* @param stdClass $report Report data.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response $response Response data.
|
||||
*/
|
||||
public function prepare_item_for_response( $report, $request ) {
|
||||
$data = array(
|
||||
'slug' => $report->slug,
|
||||
'name' => $report->name,
|
||||
'total' => $report->total,
|
||||
);
|
||||
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
|
||||
// Wrap the data in a response object.
|
||||
$response = rest_ensure_response( $data );
|
||||
|
||||
/**
|
||||
* Filter a report returned from the API.
|
||||
*
|
||||
* Allows modification of the report data right before it is returned.
|
||||
*
|
||||
* @param WP_REST_Response $response The response object.
|
||||
* @param object $report The original report object.
|
||||
* @param WP_REST_Request $request Request used to generate the response.
|
||||
*/
|
||||
return apply_filters( 'woocommerce_rest_prepare_report_products_count', $response, $report, $request );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Report's schema, conforming to JSON Schema.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_item_schema() {
|
||||
$schema = array(
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'report_product_total',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'slug' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __( 'Product type name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'total' => array(
|
||||
'description' => __( 'Amount of products.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $this->add_additional_fields_schema( $schema );
|
||||
}
|
||||
}
|
|
@ -1,132 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* REST API Reports Reviews Totals controller
|
||||
*
|
||||
* Handles requests to the /reports/reviews/count endpoint.
|
||||
*
|
||||
* @package WooCommerce/RestApi
|
||||
* @since 3.5.0
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Reports Reviews Totals controller class.
|
||||
*
|
||||
* @package WooCommerce/RestApi
|
||||
* @extends WC_REST_Reports_Controller
|
||||
*/
|
||||
class WC_REST_Report_Reviews_Totals_Controller extends WC_REST_Reports_Controller {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'wc/v3';
|
||||
|
||||
/**
|
||||
* Route base.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rest_base = 'reports/reviews/totals';
|
||||
|
||||
/**
|
||||
* Get reports list.
|
||||
*
|
||||
* @since 3.5.0
|
||||
* @return array
|
||||
*/
|
||||
protected function get_reports() {
|
||||
$data = array();
|
||||
|
||||
$query_data = array(
|
||||
'count' => true,
|
||||
'post_type' => 'product',
|
||||
'meta_key' => 'rating', // WPCS: slow query ok.
|
||||
'meta_value' => '', // WPCS: slow query ok.
|
||||
);
|
||||
|
||||
for ( $i = 1; $i <= 5; $i++ ) {
|
||||
$query_data['meta_value'] = $i;
|
||||
|
||||
$data[] = array(
|
||||
'slug' => 'rated_' . $i . '_out_of_5',
|
||||
/* translators: %s: average rating */
|
||||
'name' => sprintf( __( 'Rated %s out of 5', 'woocommerce' ), $i ),
|
||||
'total' => (int) get_comments( $query_data ),
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a report object for serialization.
|
||||
*
|
||||
* @param stdClass $report Report data.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response $response Response data.
|
||||
*/
|
||||
public function prepare_item_for_response( $report, $request ) {
|
||||
$data = array(
|
||||
'slug' => $report->slug,
|
||||
'name' => $report->name,
|
||||
'total' => $report->total,
|
||||
);
|
||||
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
|
||||
// Wrap the data in a response object.
|
||||
$response = rest_ensure_response( $data );
|
||||
|
||||
/**
|
||||
* Filter a report returned from the API.
|
||||
*
|
||||
* Allows modification of the report data right before it is returned.
|
||||
*
|
||||
* @param WP_REST_Response $response The response object.
|
||||
* @param object $report The original report object.
|
||||
* @param WP_REST_Request $request Request used to generate the response.
|
||||
*/
|
||||
return apply_filters( 'woocommerce_rest_prepare_report_reviews_count', $response, $report, $request );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Report's schema, conforming to JSON Schema.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_item_schema() {
|
||||
$schema = array(
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'report_review_total',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'slug' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __( 'Review type name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'total' => array(
|
||||
'description' => __( 'Amount of reviews.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $this->add_additional_fields_schema( $schema );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue