Reports
This commit is contained in:
parent
c6cb9d0be9
commit
f02417114f
|
@ -123,10 +123,6 @@ class Reports extends WC_REST_Controller {
|
|||
'slug' => 'downloads',
|
||||
'description' => __( 'Product downloads detailed reports.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'slug' => 'downloads/files',
|
||||
'description' => __( 'Product download files detailed reports.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'slug' => 'downloads/stats',
|
||||
'description' => __( 'Stats about product downloads.', 'woocommerce' ),
|
||||
|
@ -301,18 +297,4 @@ class Reports extends WC_REST_Controller {
|
|||
|
||||
return $order_statuses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given request has permission to read reports.
|
||||
*
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return WP_Error|boolean
|
||||
*/
|
||||
public function get_items_permissions_check( $request ) {
|
||||
if ( ! wc_rest_check_manager_permissions( 'reports', 'read' ) ) {
|
||||
return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,12 +11,12 @@ namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
|||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WC_Admin_REST_Reports_Controller;
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* REST API Category Reports class.
|
||||
* REST API Categories Reports class.
|
||||
*/
|
||||
class Categories extends WC_Admin_REST_Reports_Controller {
|
||||
class Categories extends Reports {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
|
@ -4,18 +4,19 @@
|
|||
*
|
||||
* Handles requests to the /reports/coupons/stats endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @package WooCommerce/RestApi
|
||||
*/
|
||||
|
||||
namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* REST API Reports coupons stats controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Reports_Controller
|
||||
* REST API CouponStats Reports class.
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Coupons_Stats_Controller extends WC_REST_Reports_Controller {
|
||||
class CouponStats extends Reports {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
|
@ -4,18 +4,19 @@
|
|||
*
|
||||
* Handles requests to the /reports/coupons endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @package WooCommerce/RestApi
|
||||
*/
|
||||
|
||||
namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* REST API Reports coupons controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Reports_Controller
|
||||
* REST API Coupons Reports class.
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Coupons_Controller extends WC_REST_Reports_Controller {
|
||||
class Coupons extends Reports {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
|
@ -4,18 +4,19 @@
|
|||
*
|
||||
* Handles requests to the /reports/customers/stats endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @package WooCommerce/RestApi
|
||||
*/
|
||||
|
||||
namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* REST API Reports customers stats controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Reports_Controller
|
||||
* REST API CustomerStats Reports class.
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Customers_Stats_Controller extends WC_REST_Reports_Controller {
|
||||
class CustomerStats extends Reports {
|
||||
/**
|
||||
* Endpoint namespace.
|
||||
*
|
|
@ -4,18 +4,19 @@
|
|||
*
|
||||
* Handles requests to the /reports/customers endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @package WooCommerce/RestApi
|
||||
*/
|
||||
|
||||
namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* REST API Reports customers controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Reports_Controller
|
||||
* REST API Customers Reports class.
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Customers_Controller extends WC_REST_Reports_Controller {
|
||||
class Customers extends Reports {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
|
@ -4,18 +4,19 @@
|
|||
*
|
||||
* Handles requests to the /reports/downloads/stats endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @package WooCommerce/RestApi
|
||||
*/
|
||||
|
||||
namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* REST API Reports downloads stats controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Reports_Controller
|
||||
* REST API DownloadStats Reports class.
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Downloads_Stats_Controller extends WC_REST_Reports_Controller {
|
||||
class DownloadStats extends Reports {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
|
@ -4,18 +4,19 @@
|
|||
*
|
||||
* Handles requests to the /reports/downloads endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @package WooCommerce/RestApi
|
||||
*/
|
||||
|
||||
namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* REST API Reports downloads controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Reports_Controller
|
||||
* REST API Downloads Reports class.
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Downloads_Controller extends WC_Admin_REST_Reports_Controller {
|
||||
class Downloads extends Reports {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
|
@ -4,18 +4,19 @@
|
|||
*
|
||||
* Handles requests to /reports/import
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @package WooCommerce/RestApi
|
||||
*/
|
||||
|
||||
namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* Reports Imports controller.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @extends WC_REST_Data_Controller
|
||||
* REST API Import Reports class.
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Import_Controller extends WC_Admin_REST_Reports_Controller {
|
||||
class Import extends Reports {
|
||||
/**
|
||||
* Endpoint namespace.
|
||||
*
|
|
@ -4,18 +4,19 @@
|
|||
*
|
||||
* Handles requests to the /reports/orders/stats endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @package WooCommerce/RestApi
|
||||
*/
|
||||
|
||||
namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* REST API Reports orders stats controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_Admin_REST_Reports_Controller
|
||||
* REST API OrderStats Reports class.
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Orders_Stats_Controller extends WC_Admin_REST_Reports_Controller {
|
||||
class OrderStats extends Reports {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
|
@ -4,18 +4,19 @@
|
|||
*
|
||||
* Handles requests to the /reports/orders endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @package WooCommerce/RestApi
|
||||
*/
|
||||
|
||||
namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* REST API Reports orders controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_Admin_REST_Reports_Controller
|
||||
* REST API Orders Reports class.
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Orders_Controller extends WC_Admin_REST_Reports_Controller {
|
||||
class Orders extends Reports {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
|
@ -4,18 +4,19 @@
|
|||
*
|
||||
* Handles requests to the /reports/store-performance endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @package WooCommerce/RestApi
|
||||
*/
|
||||
|
||||
namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* REST API Reports Performance indicators controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Reports_Controller
|
||||
* REST API PerformanceIndicators class.
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Performance_Indicators_Controller extends WC_REST_Reports_Controller {
|
||||
class PerformanceIndicators extends Reports {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
|
@ -4,18 +4,19 @@
|
|||
*
|
||||
* Handles requests to the /reports/products/stats endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @package WooCommerce/RestApi
|
||||
*/
|
||||
|
||||
namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* REST API Reports products stats controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Reports_Controller
|
||||
* REST API ProductStats Reports class.
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Products_Stats_Controller extends WC_REST_Reports_Controller {
|
||||
class ProductStats extends Reports {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
|
@ -4,18 +4,19 @@
|
|||
*
|
||||
* Handles requests to the /reports/products endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @package WooCommerce/RestApi
|
||||
*/
|
||||
|
||||
namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* REST API Reports products controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Reports_Controller
|
||||
* REST API Products Reports class.
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Products_Controller extends WC_REST_Reports_Controller {
|
||||
class Products extends Reports {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
|
@ -4,18 +4,19 @@
|
|||
*
|
||||
* Handles requests to the /reports/revenue/stats endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @package WooCommerce/RestApi
|
||||
*/
|
||||
|
||||
namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* REST API Reports revenue stats controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Reports_Controller
|
||||
* REST API RevenueStats Reports class.
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Revenue_Stats_Controller extends WC_REST_Reports_Controller {
|
||||
class RevenueStats extends Reports {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
|
@ -4,18 +4,19 @@
|
|||
*
|
||||
* Handles requests to the /reports/stock endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @package WooCommerce/RestApi
|
||||
*/
|
||||
|
||||
namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* REST API Reports stock controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Reports_Controller
|
||||
* REST API Stock Reports class.
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Stock_Controller extends WC_REST_Reports_Controller {
|
||||
class Stock extends Reports {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
|
@ -4,18 +4,19 @@
|
|||
*
|
||||
* Handles requests to the /reports/stock/stats endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @package WooCommerce/RestApi
|
||||
*/
|
||||
|
||||
namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* REST API Reports stock stats controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Reports_Controller
|
||||
* REST API StockStats Reports class.
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Stock_Stats_Controller extends WC_REST_Reports_Controller {
|
||||
class StockStats extends Reports {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
|
@ -4,18 +4,19 @@
|
|||
*
|
||||
* Handles requests to the /reports/taxes/stats endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @package WooCommerce/RestApi
|
||||
*/
|
||||
|
||||
namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* REST API Reports taxes stats controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Reports_Controller
|
||||
* REST API TaxesStats Reports class.
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Taxes_Stats_Controller extends WC_REST_Reports_Controller {
|
||||
class TaxStats extends Reports {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
|
@ -4,18 +4,19 @@
|
|||
*
|
||||
* Handles requests to the /reports/taxes endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @package WooCommerce/RestApi
|
||||
*/
|
||||
|
||||
namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* REST API Reports taxes controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Reports_Controller
|
||||
* REST API Taxes Reports class.
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Taxes_Controller extends WC_REST_Reports_Controller {
|
||||
class Taxes extends Reports {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
|
@ -4,18 +4,19 @@
|
|||
*
|
||||
* Handles requests to the /reports/products endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @package WooCommerce/RestApi
|
||||
*/
|
||||
|
||||
namespace WooCommerce\RestApi\Version4\Controllers\Reports;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use \WooCommerce\RestApi\Version4\Controllers\Reports as Reports;
|
||||
|
||||
/**
|
||||
* REST API Reports products controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Reports_Controller
|
||||
* REST API Variations Reports class.
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Variations_Controller extends WC_REST_Reports_Controller {
|
||||
class Variations extends Reports {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
|
@ -1,303 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* REST API Reports controller extended by WC Admin plugin.
|
||||
*
|
||||
* Handles requests to the reports endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Reports controller class.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
* @extends WC_REST_Reports_Controller
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Controller extends WC_REST_Reports_Controller {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'wc/v4';
|
||||
|
||||
/**
|
||||
* Route base.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rest_base = 'reports';
|
||||
|
||||
/**
|
||||
* Register the routes for reports.
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given request has permission to read reports.
|
||||
*
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return WP_Error|boolean
|
||||
*/
|
||||
public function get_items_permissions_check( $request ) {
|
||||
if ( ! wc_rest_check_manager_permissions( 'reports', 'read' ) ) {
|
||||
return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all reports.
|
||||
*
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$data = array();
|
||||
$reports = array(
|
||||
array(
|
||||
'slug' => 'performance-indicators',
|
||||
'description' => __( 'Batch endpoint for getting specific performance indicators from `stats` endpoints.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'slug' => 'revenue/stats',
|
||||
'description' => __( 'Stats about revenue.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'slug' => 'orders/stats',
|
||||
'description' => __( 'Stats about orders.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'slug' => 'products',
|
||||
'description' => __( 'Products detailed reports.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'slug' => 'products/stats',
|
||||
'description' => __( 'Stats about products.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'slug' => 'categories',
|
||||
'description' => __( 'Product categories detailed reports.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'slug' => 'categories/stats',
|
||||
'description' => __( 'Stats about product categories.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'slug' => 'coupons',
|
||||
'description' => __( 'Coupons detailed reports.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'slug' => 'coupons/stats',
|
||||
'description' => __( 'Stats about coupons.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'slug' => 'taxes',
|
||||
'description' => __( 'Taxes detailed reports.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'slug' => 'taxes/stats',
|
||||
'description' => __( 'Stats about taxes.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'slug' => 'downloads',
|
||||
'description' => __( 'Product downloads detailed reports.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'slug' => 'downloads/files',
|
||||
'description' => __( 'Product download files detailed reports.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'slug' => 'downloads/stats',
|
||||
'description' => __( 'Stats about product downloads.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'slug' => 'customers',
|
||||
'description' => __( 'Customers detailed reports.', 'woocommerce' ),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter the list of allowed reports, so that data can be loaded from third party extensions in addition to WooCommerce core.
|
||||
* Array items should be in format of array( 'slug' => 'downloads/stats', 'description' => '',
|
||||
* 'url' => '', and 'path' => '/wc-ext/v1/...'.
|
||||
*
|
||||
* @param array $endpoints The list of allowed reports..
|
||||
*/
|
||||
$reports = apply_filters( 'woocommerce_admin_reports', $reports );
|
||||
|
||||
foreach ( $reports as $report ) {
|
||||
if ( empty( $report['slug'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( empty( $report['path'] ) ) {
|
||||
$report['path'] = '/' . $this->namespace . '/reports/' . $report['slug'];
|
||||
}
|
||||
|
||||
// Allows a different admin page to be loaded here,
|
||||
// or allows an empty url if no report exists for a set of performance indicators.
|
||||
if ( ! isset( $report['url'] ) ) {
|
||||
if ( '/stats' === substr( $report['slug'], -6 ) ) {
|
||||
$url_slug = substr( $report['slug'], 0, -6 );
|
||||
} else {
|
||||
$url_slug = $report['slug'];
|
||||
}
|
||||
|
||||
$report['url'] = '/analytics/' . $url_slug;
|
||||
}
|
||||
|
||||
$item = $this->prepare_item_for_response( (object) $report, $request );
|
||||
$data[] = $this->prepare_response_for_collection( $item );
|
||||
}
|
||||
|
||||
return rest_ensure_response( $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the order number for an order. If no filter is present for `woocommerce_order_number`, we can just return the ID.
|
||||
* Returns the parent order number if the order is actually a refund.
|
||||
*
|
||||
* @param int $order_id Order ID.
|
||||
* @return string
|
||||
*/
|
||||
public function get_order_number( $order_id ) {
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
if ( 'shop_order_refund' === $order->get_type() ) {
|
||||
$order = wc_get_order( $order->get_parent_id() );
|
||||
}
|
||||
|
||||
if ( ! has_filter( 'woocommerce_order_number' ) ) {
|
||||
return $order->get_id();
|
||||
}
|
||||
|
||||
return $order->get_order_number();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a report object for serialization.
|
||||
*
|
||||
* @param stdClass $report Report data.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public function prepare_item_for_response( $report, $request ) {
|
||||
$data = array(
|
||||
'slug' => $report->slug,
|
||||
'description' => $report->description,
|
||||
'path' => $report->path,
|
||||
);
|
||||
|
||||
$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 );
|
||||
$response->add_links(
|
||||
array(
|
||||
'self' => array(
|
||||
'href' => rest_url( $report->path ),
|
||||
),
|
||||
'report' => array(
|
||||
'href' => $report->url,
|
||||
),
|
||||
'collection' => array(
|
||||
'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* 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', $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',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'slug' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'description' => array(
|
||||
'description' => __( 'A human-readable description of the resource.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'path' => array(
|
||||
'description' => __( 'API path.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $this->add_additional_fields_schema( $schema );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the query params for collections.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_collection_params() {
|
||||
return array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get order statuses without prefixes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_order_statuses() {
|
||||
$order_statuses = array();
|
||||
|
||||
foreach ( array_keys( wc_get_order_statuses() ) as $status ) {
|
||||
$order_statuses[] = str_replace( 'wc-', '', $status );
|
||||
}
|
||||
|
||||
return $order_statuses;
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* REST API Reports downloads files controller
|
||||
*
|
||||
* Handles requests to the /reports/downloads/files endpoint.
|
||||
*
|
||||
* @package WooCommerce Admin/API
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Reports downloads files controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Reports_Controller
|
||||
*/
|
||||
class WC_Admin_REST_Reports_Downloads_Files_Controller extends WC_REST_Reports_Controller {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'wc/v4';
|
||||
|
||||
/**
|
||||
* Route base.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rest_base = 'reports/downloads/files';
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
# REST API v4 Changelog
|
||||
# REST API v4 Change-log
|
||||
|
||||
## Changes
|
||||
|
||||
|
@ -13,6 +13,24 @@
|
|||
## New endpoints
|
||||
|
||||
- Added `reports/products` endpoint.
|
||||
- Added `reports/products/stats` endpoint.
|
||||
- Added `reports/categories` endpoint.
|
||||
- Added `reports/orders` endpoint.
|
||||
- Added `reports/orders/stats` endpoint.
|
||||
- Added `reports/performance-indicators` endpoint.
|
||||
- Added `reports/revenue/stats` endpoint.
|
||||
- Added `reports/stock` endpoint.
|
||||
- Added `reports/stock/stats` endpoint.
|
||||
- Added `reports/taxes` endpoint.
|
||||
- Added `reports/taxes/stats` endpoint.
|
||||
- Added `reports/variations` endpoint.
|
||||
- Added `reports/coupons` endpoint.
|
||||
- Added `reports/coupons/stats` endpoint.
|
||||
- Added `reports/customer` endpoint.
|
||||
- Added `reports/customers/stats` endpoint.
|
||||
- Added `reports/downloads` endpoint.
|
||||
- Added `reports/downloads/stats` endpoint.
|
||||
- Added `reports/import` endpoint.
|
||||
|
||||
## Removed endpoints
|
||||
|
||||
|
|
Loading…
Reference in New Issue