Update all wc-admin endpoints to v4 (https://github.com/woocommerce/woocommerce-admin/pull/1298)
* Update all wc-admin endpoints to v4 * Add namespace for products and customers controllers * Include product quantity in orders data store * Add coupons to extended data in the orders data store * Format order statuses response from database * Hook up orders table to orders endpoint * Add namespace to data endpoint controller * Add namespaces to remaining extended controllers * Use NAMESPACE var in place of wc/v4 * Update product links in orders table to products reports * Add coupons rest controller override * Format coupon code in response Co-Authored-By: joshuatf <joshuatf@gmail.com>
This commit is contained in:
parent
11ddae699a
commit
7cdbbf87e8
|
@ -14,7 +14,7 @@ And as such will require data layer logic for products to fully build the table
|
||||||
"_links": {
|
"_links": {
|
||||||
"product": [
|
"product": [
|
||||||
{
|
{
|
||||||
"href": "https://example.com/wp-json/wc/v3/products/20"
|
"href": "https://example.com/wp-json/wc/v4/products/20"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ export default [
|
||||||
_links: {
|
_links: {
|
||||||
product: [
|
product: [
|
||||||
{
|
{
|
||||||
href: 'https://example.com/wp-json/wc/v3/products/20',
|
href: 'https://example.com/wp-json/wc/v4/products/20',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -46,7 +46,7 @@ export default [
|
||||||
_links: {
|
_links: {
|
||||||
product: [
|
product: [
|
||||||
{
|
{
|
||||||
href: 'https://example.com/wp-json/wc/v3/products/22',
|
href: 'https://example.com/wp-json/wc/v4/products/22',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -60,7 +60,7 @@ export default [
|
||||||
_links: {
|
_links: {
|
||||||
product: [
|
product: [
|
||||||
{
|
{
|
||||||
href: 'https://example.com/wp-json/wc/v3/products/23',
|
href: 'https://example.com/wp-json/wc/v4/products/23',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -74,7 +74,7 @@ export default [
|
||||||
_links: {
|
_links: {
|
||||||
product: [
|
product: [
|
||||||
{
|
{
|
||||||
href: 'https://example.com/wp-json/wc/v3/products/24',
|
href: 'https://example.com/wp-json/wc/v4/products/24',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -88,7 +88,7 @@ export default [
|
||||||
_links: {
|
_links: {
|
||||||
product: [
|
product: [
|
||||||
{
|
{
|
||||||
href: 'https://example.com/wp-json/wc/v3/products/25',
|
href: 'https://example.com/wp-json/wc/v4/products/25',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -69,7 +69,7 @@ Leaderboard.propTypes = {
|
||||||
/**
|
/**
|
||||||
* The endpoint to use in API calls to populate the table rows and summary.
|
* The endpoint to use in API calls to populate the table rows and summary.
|
||||||
* For example, if `taxes` is provided, data will be fetched from the report
|
* For example, if `taxes` is provided, data will be fetched from the report
|
||||||
* `taxes` endpoint (ie: `/wc/v3/reports/taxes` and `/wc/v3/reports/taxes/stats`).
|
* `taxes` endpoint (ie: `/wc/v4/reports/taxes` and `/wc/v4/reports/taxes/stats`).
|
||||||
* If the provided endpoint doesn't exist, an error will be shown to the user
|
* If the provided endpoint doesn't exist, an error will be shown to the user
|
||||||
* with `ReportError`.
|
* with `ReportError`.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -17,6 +17,7 @@ import { formatCurrency, getCurrencyFormatDecimal } from '@woocommerce/currency'
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import LeaderboardWithSelect, { Leaderboard } from '../';
|
import LeaderboardWithSelect, { Leaderboard } from '../';
|
||||||
|
import { NAMESPACE } from 'store/constants';
|
||||||
import { numberFormat } from 'lib/number';
|
import { numberFormat } from 'lib/number';
|
||||||
import mockData from '../__mocks__/top-selling-products-mock-data';
|
import mockData from '../__mocks__/top-selling-products-mock-data';
|
||||||
|
|
||||||
|
@ -102,7 +103,7 @@ describe( 'Leaderboard', () => {
|
||||||
);
|
);
|
||||||
const leaderboard = leaderboardWrapper.root.findByType( Leaderboard );
|
const leaderboard = leaderboardWrapper.root.findByType( Leaderboard );
|
||||||
|
|
||||||
const endpoint = '/wc/v3/reports/products';
|
const endpoint = NAMESPACE + 'reports/products';
|
||||||
const query = { orderby: 'items_sold', per_page: 5, extended_info: 1 };
|
const query = { orderby: 'items_sold', per_page: 5, extended_info: 1 };
|
||||||
|
|
||||||
expect( getReportStatsMock.mock.calls[ 0 ][ 1 ] ).toBe( endpoint );
|
expect( getReportStatsMock.mock.calls[ 0 ][ 1 ] ).toBe( endpoint );
|
||||||
|
|
|
@ -80,7 +80,7 @@ ReportSummary.propTypes = {
|
||||||
/**
|
/**
|
||||||
* The endpoint to use in API calls to populate the Summary Numbers.
|
* The endpoint to use in API calls to populate the Summary Numbers.
|
||||||
* For example, if `taxes` is provided, data will be fetched from the report
|
* For example, if `taxes` is provided, data will be fetched from the report
|
||||||
* `taxes` endpoint (ie: `/wc/v3/reports/taxes/stats`). If the provided endpoint
|
* `taxes` endpoint (ie: `/wc/v4/reports/taxes/stats`). If the provided endpoint
|
||||||
* doesn't exist, an error will be shown to the user with `ReportError`.
|
* doesn't exist, an error will be shown to the user with `ReportError`.
|
||||||
*/
|
*/
|
||||||
endpoint: PropTypes.string.isRequired,
|
endpoint: PropTypes.string.isRequired,
|
||||||
|
|
|
@ -124,7 +124,7 @@ ReportTable.propTypes = {
|
||||||
/**
|
/**
|
||||||
* The endpoint to use in API calls to populate the table rows and summary.
|
* The endpoint to use in API calls to populate the table rows and summary.
|
||||||
* For example, if `taxes` is provided, data will be fetched from the report
|
* For example, if `taxes` is provided, data will be fetched from the report
|
||||||
* `taxes` endpoint (ie: `/wc/v3/reports/taxes` and `/wc/v3/reports/taxes/stats`).
|
* `taxes` endpoint (ie: `/wc/v4/reports/taxes` and `/wc/v4/reports/taxes/stats`).
|
||||||
* If the provided endpoint doesn't exist, an error will be shown to the user
|
* If the provided endpoint doesn't exist, an error will be shown to the user
|
||||||
* with `ReportError`.
|
* with `ReportError`.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,30 +2,25 @@
|
||||||
/**
|
/**
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { __, _n, sprintf } from '@wordpress/i18n';
|
import { __, _n, _x, sprintf } from '@wordpress/i18n';
|
||||||
import { Component, Fragment } from '@wordpress/element';
|
import { Component, Fragment } from '@wordpress/element';
|
||||||
import { compose } from '@wordpress/compose';
|
|
||||||
import { map } from 'lodash';
|
import { map } from 'lodash';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WooCommerce dependencies
|
* WooCommerce dependencies
|
||||||
*/
|
*/
|
||||||
import { appendTimestamp, defaultTableDateFormat, getCurrentDates } from '@woocommerce/date';
|
|
||||||
import { Date, Link, OrderStatus, ViewMoreList } from '@woocommerce/components';
|
import { Date, Link, OrderStatus, ViewMoreList } from '@woocommerce/components';
|
||||||
|
import { defaultTableDateFormat } from '@woocommerce/date';
|
||||||
import { formatCurrency } from '@woocommerce/currency';
|
import { formatCurrency } from '@woocommerce/currency';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { QUERY_DEFAULTS } from 'store/constants';
|
|
||||||
import { getFilterQuery } from 'store/reports/utils';
|
|
||||||
import { numberFormat } from 'lib/number';
|
import { numberFormat } from 'lib/number';
|
||||||
import withSelect from 'wc-api/with-select';
|
|
||||||
import ReportTable from 'analytics/components/report-table';
|
import ReportTable from 'analytics/components/report-table';
|
||||||
import { formatTableOrders } from './utils';
|
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
class OrdersReportTable extends Component {
|
export default class OrdersReportTable extends Component {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
@ -98,26 +93,27 @@ class OrdersReportTable extends Component {
|
||||||
getRowsContent( tableData ) {
|
getRowsContent( tableData ) {
|
||||||
return map( tableData, row => {
|
return map( tableData, row => {
|
||||||
const {
|
const {
|
||||||
date,
|
currency,
|
||||||
id,
|
customer_type,
|
||||||
|
date_created,
|
||||||
|
extended_info,
|
||||||
|
net_total,
|
||||||
|
num_items_sold,
|
||||||
|
order_id,
|
||||||
status,
|
status,
|
||||||
customer_id,
|
|
||||||
line_items,
|
|
||||||
items_sold,
|
|
||||||
coupon_lines,
|
|
||||||
currency_symbol,
|
|
||||||
net_revenue,
|
|
||||||
} = row;
|
} = row;
|
||||||
|
const { coupons, products } = extended_info;
|
||||||
|
|
||||||
const products = line_items
|
const formattedProducts = products
|
||||||
.sort( ( itemA, itemB ) => itemB.quantity - itemA.quantity )
|
.sort( ( itemA, itemB ) => itemB.quantity - itemA.quantity )
|
||||||
.map( item => ( {
|
.map( item => ( {
|
||||||
label: item.name,
|
label: item.name,
|
||||||
href: 'post.php?post=' + item.product_id + '&action=edit',
|
href:
|
||||||
|
'admin.php?page=wc-admin#/analytics/products?filter=single_product&products=' + item.id,
|
||||||
quantity: item.quantity,
|
quantity: item.quantity,
|
||||||
} ) );
|
} ) );
|
||||||
|
|
||||||
const coupons = coupon_lines.map( coupon => ( {
|
const formattedCoupons = coupons.map( coupon => ( {
|
||||||
label: coupon.code,
|
label: coupon.code,
|
||||||
// @TODO It should link to the coupons report
|
// @TODO It should link to the coupons report
|
||||||
href: 'edit.php?s=' + coupon.code + '&post_type=shop_coupon',
|
href: 'edit.php?s=' + coupon.code + '&post_type=shop_coupon',
|
||||||
|
@ -125,16 +121,16 @@ class OrdersReportTable extends Component {
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
display: <Date date={ date } visibleFormat={ defaultTableDateFormat } />,
|
display: <Date date={ date_created } visibleFormat={ defaultTableDateFormat } />,
|
||||||
value: date,
|
value: date_created,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
display: (
|
display: (
|
||||||
<Link href={ 'post.php?post=' + id + '&action=edit' } type="wp-admin">
|
<Link href={ 'post.php?post=' + order_id + '&action=edit' } type="wp-admin">
|
||||||
{ id }
|
{ order_id }
|
||||||
</Link>
|
</Link>
|
||||||
),
|
),
|
||||||
value: id,
|
value: order_id,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
display: (
|
display: (
|
||||||
|
@ -143,32 +139,36 @@ class OrdersReportTable extends Component {
|
||||||
value: status,
|
value: status,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// @TODO This should display customer type (new/returning) once it's
|
display:
|
||||||
// implemented in the API.
|
customer_type === 'new'
|
||||||
display: customer_id,
|
? _x( 'New', 'customer type', 'wc-admin' )
|
||||||
value: customer_id,
|
: _x( 'Returning', 'customer type', 'wc-admin' ),
|
||||||
|
value: customer_type,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
display: this.renderList(
|
display: this.renderList(
|
||||||
products.length ? [ products[ 0 ] ] : [],
|
formattedProducts.length ? [ formattedProducts[ 0 ] ] : [],
|
||||||
products.map( product => ( {
|
formattedProducts.map( product => ( {
|
||||||
label: sprintf( __( '%s× %s', 'wc-admin' ), product.quantity, product.label ),
|
label: sprintf( __( '%s× %s', 'wc-admin' ), product.quantity, product.label ),
|
||||||
href: product.href,
|
href: product.href,
|
||||||
} ) )
|
} ) )
|
||||||
),
|
),
|
||||||
value: products.map( product => product.label ).join( ' ' ),
|
value: formattedProducts.map( product => product.label ).join( ' ' ),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
display: numberFormat( items_sold ),
|
display: numberFormat( num_items_sold ),
|
||||||
value: items_sold,
|
value: num_items_sold,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
display: this.renderList( coupons.length ? [ coupons[ 0 ] ] : [], coupons ),
|
display: this.renderList(
|
||||||
value: coupons.map( item => item.code ).join( ' ' ),
|
formattedCoupons.length ? [ formattedCoupons[ 0 ] ] : [],
|
||||||
|
formattedCoupons
|
||||||
|
),
|
||||||
|
value: formattedCoupons.map( item => item.code ).join( ' ' ),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
display: formatCurrency( net_revenue, currency_symbol ),
|
display: formatCurrency( net_total, currency ),
|
||||||
value: net_revenue,
|
value: net_total,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
} );
|
} );
|
||||||
|
@ -233,7 +233,7 @@ class OrdersReportTable extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { query, tableData } = this.props;
|
const { query } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ReportTable
|
<ReportTable
|
||||||
|
@ -242,49 +242,12 @@ class OrdersReportTable extends Component {
|
||||||
getRowsContent={ this.getRowsContent }
|
getRowsContent={ this.getRowsContent }
|
||||||
getSummary={ this.getSummary }
|
getSummary={ this.getSummary }
|
||||||
query={ query }
|
query={ query }
|
||||||
tableData={ tableData }
|
tableQuery={ {
|
||||||
|
extended_info: true,
|
||||||
|
} }
|
||||||
title={ __( 'Orders', 'wc-admin' ) }
|
title={ __( 'Orders', 'wc-admin' ) }
|
||||||
columnPrefsKey="orders_report_columns"
|
columnPrefsKey="orders_report_columns"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default compose(
|
|
||||||
withSelect( ( select, props ) => {
|
|
||||||
const { query } = props;
|
|
||||||
const datesFromQuery = getCurrentDates( query );
|
|
||||||
const filterQuery = getFilterQuery( 'orders', query );
|
|
||||||
|
|
||||||
const { getOrders, getOrdersTotalCount, getOrdersError, isGetOrdersRequesting } = select(
|
|
||||||
'wc-api'
|
|
||||||
);
|
|
||||||
|
|
||||||
const tableQuery = {
|
|
||||||
orderby: query.orderby || 'date',
|
|
||||||
order: query.order || 'desc',
|
|
||||||
page: query.page || 1,
|
|
||||||
per_page: query.per_page || QUERY_DEFAULTS.pageSize,
|
|
||||||
after: appendTimestamp( datesFromQuery.primary.after, 'start' ),
|
|
||||||
before: appendTimestamp( datesFromQuery.primary.before, 'end' ),
|
|
||||||
status: [ 'processing', 'on-hold', 'completed' ],
|
|
||||||
...filterQuery,
|
|
||||||
};
|
|
||||||
const orders = getOrders( tableQuery );
|
|
||||||
const ordersTotalCount = getOrdersTotalCount( tableQuery );
|
|
||||||
const isError = Boolean( getOrdersError( tableQuery ) );
|
|
||||||
const isRequesting = isGetOrdersRequesting( tableQuery );
|
|
||||||
|
|
||||||
return {
|
|
||||||
tableData: {
|
|
||||||
items: {
|
|
||||||
data: formatTableOrders( orders ),
|
|
||||||
totalResults: ordersTotalCount,
|
|
||||||
},
|
|
||||||
isError,
|
|
||||||
isRequesting,
|
|
||||||
query: tableQuery,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
} )
|
|
||||||
)( OrdersReportTable );
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const NAMESPACE = '/wc/v3/';
|
export const NAMESPACE = '/wc/v4/';
|
||||||
export const SWAGGERNAMESPACE = 'https://virtserver.swaggerhub.com/peterfabian/wc-v3-api/1.0.0/';
|
export const SWAGGERNAMESPACE = 'https://virtserver.swaggerhub.com/peterfabian/wc-v3-api/1.0.0/';
|
||||||
export const ERROR = 'ERROR';
|
export const ERROR = 'ERROR';
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { dispatch } from '@wordpress/data';
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
|
import { NAMESPACE } from 'store/constants';
|
||||||
import resolvers from '../resolvers';
|
import resolvers from '../resolvers';
|
||||||
|
|
||||||
const { getNotes } = resolvers;
|
const { getNotes } = resolvers;
|
||||||
|
@ -29,10 +30,10 @@ describe( 'getNotes', () => {
|
||||||
|
|
||||||
beforeAll( () => {
|
beforeAll( () => {
|
||||||
apiFetch.mockImplementation( options => {
|
apiFetch.mockImplementation( options => {
|
||||||
if ( options.path === '/wc/v3/admin/notes' ) {
|
if ( options.path === NAMESPACE + 'admin/notes' ) {
|
||||||
return Promise.resolve( NOTES_1 );
|
return Promise.resolve( NOTES_1 );
|
||||||
}
|
}
|
||||||
if ( options.path === '/wc/v3/admin/notes?page=2' ) {
|
if ( options.path === NAMESPACE + 'admin/notes?page=2' ) {
|
||||||
return Promise.resolve( NOTES_2 );
|
return Promise.resolve( NOTES_2 );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { dispatch } from '@wordpress/data';
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
|
import { NAMESPACE } from 'store/constants';
|
||||||
import resolvers from '../resolvers';
|
import resolvers from '../resolvers';
|
||||||
|
|
||||||
const { getOrders } = resolvers;
|
const { getOrders } = resolvers;
|
||||||
|
@ -29,10 +30,10 @@ describe( 'getOrders', () => {
|
||||||
|
|
||||||
beforeAll( () => {
|
beforeAll( () => {
|
||||||
apiFetch.mockImplementation( options => {
|
apiFetch.mockImplementation( options => {
|
||||||
if ( options.path === '/wc/v3/orders' ) {
|
if ( options.path === NAMESPACE + 'orders' ) {
|
||||||
return Promise.resolve( ORDERS_1 );
|
return Promise.resolve( ORDERS_1 );
|
||||||
}
|
}
|
||||||
if ( options.path === '/wc/v3/orders?orderby=id' ) {
|
if ( options.path === NAMESPACE + 'orders?orderby=id' ) {
|
||||||
return Promise.resolve( ORDERS_2 );
|
return Promise.resolve( ORDERS_2 );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -31,7 +31,7 @@ describe( 'getReportItems', () => {
|
||||||
|
|
||||||
beforeAll( () => {
|
beforeAll( () => {
|
||||||
apiFetch.mockImplementation( options => {
|
apiFetch.mockImplementation( options => {
|
||||||
if ( options.path === `/wc/v3/reports/${ endpoint }` ) {
|
if ( options.path === `/wc/v4/reports/${ endpoint }` ) {
|
||||||
return Promise.resolve( {
|
return Promise.resolve( {
|
||||||
headers: {
|
headers: {
|
||||||
get: () => ITEMS_1_COUNT,
|
get: () => ITEMS_1_COUNT,
|
||||||
|
@ -39,7 +39,7 @@ describe( 'getReportItems', () => {
|
||||||
json: () => Promise.resolve( ITEMS_1 ),
|
json: () => Promise.resolve( ITEMS_1 ),
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
if ( options.path === `/wc/v3/reports/${ endpoint }?orderby=id` ) {
|
if ( options.path === `/wc/v4/reports/${ endpoint }?orderby=id` ) {
|
||||||
return Promise.resolve( {
|
return Promise.resolve( {
|
||||||
headers: {
|
headers: {
|
||||||
get: () => ITEMS_2_COUNT,
|
get: () => ITEMS_2_COUNT,
|
||||||
|
|
|
@ -55,7 +55,7 @@ describe( 'getReportStats', () => {
|
||||||
|
|
||||||
beforeAll( () => {
|
beforeAll( () => {
|
||||||
apiFetch.mockImplementation( options => {
|
apiFetch.mockImplementation( options => {
|
||||||
if ( options.path === '/wc/v3/reports/revenue/stats' ) {
|
if ( options.path === '/wc/v4/reports/revenue/stats' ) {
|
||||||
return Promise.resolve( {
|
return Promise.resolve( {
|
||||||
headers: {
|
headers: {
|
||||||
get: header => REPORT_1_TOTALS[ header ],
|
get: header => REPORT_1_TOTALS[ header ],
|
||||||
|
@ -63,7 +63,7 @@ describe( 'getReportStats', () => {
|
||||||
json: () => Promise.resolve( REPORT_1 ),
|
json: () => Promise.resolve( REPORT_1 ),
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
if ( options.path === '/wc/v3/reports/products/stats?interval=week' ) {
|
if ( options.path === '/wc/v4/reports/products/stats?interval=week' ) {
|
||||||
return Promise.resolve( {
|
return Promise.resolve( {
|
||||||
headers: {
|
headers: {
|
||||||
get: header => REPORT_2_TOTALS[ header ],
|
get: header => REPORT_2_TOTALS[ header ],
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*/
|
*/
|
||||||
import { SECOND, MINUTE } from '@fresh-data/framework';
|
import { SECOND, MINUTE } from '@fresh-data/framework';
|
||||||
|
|
||||||
export const NAMESPACE = '/wc/v3';
|
export const NAMESPACE = '/wc/v4';
|
||||||
|
|
||||||
export const DEFAULT_REQUIREMENT = {
|
export const DEFAULT_REQUIREMENT = {
|
||||||
timeout: 5 * SECOND,
|
timeout: 5 * SECOND,
|
||||||
|
|
|
@ -22,7 +22,7 @@ Properties of all the charts available for that report.
|
||||||
|
|
||||||
The endpoint to use in API calls to populate the Summary Numbers.
|
The endpoint to use in API calls to populate the Summary Numbers.
|
||||||
For example, if `taxes` is provided, data will be fetched from the report
|
For example, if `taxes` is provided, data will be fetched from the report
|
||||||
`taxes` endpoint (ie: `/wc/v3/reports/taxes/stats`). If the provided endpoint
|
`taxes` endpoint (ie: `/wc/v4/reports/taxes/stats`). If the provided endpoint
|
||||||
doesn't exist, an error will be shown to the user with `ReportError`.
|
doesn't exist, an error will be shown to the user with `ReportError`.
|
||||||
|
|
||||||
### `query`
|
### `query`
|
||||||
|
|
|
@ -20,7 +20,7 @@ The key for user preferences settings for column visibility.
|
||||||
|
|
||||||
The endpoint to use in API calls to populate the table rows and summary.
|
The endpoint to use in API calls to populate the table rows and summary.
|
||||||
For example, if `taxes` is provided, data will be fetched from the report
|
For example, if `taxes` is provided, data will be fetched from the report
|
||||||
`taxes` endpoint (ie: `/wc/v3/reports/taxes` and `/wc/v3/reports/taxes/stats`).
|
`taxes` endpoint (ie: `/wc/v4/reports/taxes` and `/wc/v4/reports/taxes/stats`).
|
||||||
If the provided endpoint doesn't exist, an error will be shown to the user
|
If the provided endpoint doesn't exist, an error will be shown to the user
|
||||||
with `ReportError`.
|
with `ReportError`.
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_Admin_Notes_Controller extends WC_REST_CRUD_Controller {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* REST API Coupons Controller
|
||||||
|
*
|
||||||
|
* Handles requests to /coupons/*
|
||||||
|
*
|
||||||
|
* @package WooCommerce Admin/API
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Coupons controller.
|
||||||
|
*
|
||||||
|
* @package WooCommerce Admin/API
|
||||||
|
* @extends WC_REST_Coupons_Controller
|
||||||
|
*/
|
||||||
|
class WC_Admin_REST_Coupons_Controller extends WC_REST_Coupons_Controller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoint namespace.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
|
}
|
|
@ -19,6 +19,13 @@ class WC_Admin_REST_Customers_Controller extends WC_REST_Customers_Controller {
|
||||||
|
|
||||||
// TODO Add support for guests here. See https://wp.me/p7bje6-1dM.
|
// TODO Add support for guests here. See https://wp.me/p7bje6-1dM.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoint namespace.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches emails by partial search instead of a strict match.
|
* Searches emails by partial search instead of a strict match.
|
||||||
* See "search parameters" under https://codex.wordpress.org/Class_Reference/WP_User_Query.
|
* See "search parameters" under https://codex.wordpress.org/Class_Reference/WP_User_Query.
|
||||||
|
|
|
@ -17,6 +17,13 @@ defined( 'ABSPATH' ) || exit;
|
||||||
*/
|
*/
|
||||||
class WC_Admin_REST_Data_Controller extends WC_REST_Data_Controller {
|
class WC_Admin_REST_Data_Controller extends WC_REST_Data_Controller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoint namespace.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the list of data resources.
|
* Return the list of data resources.
|
||||||
*
|
*
|
||||||
|
|
|
@ -21,7 +21,7 @@ class WC_Admin_REST_Data_Download_Ips_Controller extends WC_REST_Data_Controller
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
|
|
@ -15,7 +15,14 @@ defined( 'ABSPATH' ) || exit;
|
||||||
* @package WooCommerce Admin/API
|
* @package WooCommerce Admin/API
|
||||||
* @extends WC_REST_Orders_Controller
|
* @extends WC_REST_Orders_Controller
|
||||||
*/
|
*/
|
||||||
class WC_Admin_REST_Orders_Stats_Controller extends WC_REST_Orders_Controller {
|
class WC_Admin_REST_Orders_Controller extends WC_REST_Orders_Controller {
|
||||||
|
/**
|
||||||
|
* Endpoint namespace.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the query params for collections.
|
* Get the query params for collections.
|
||||||
*
|
*
|
|
@ -16,6 +16,12 @@ defined( 'ABSPATH' ) || exit;
|
||||||
* @extends WC_REST_Product_Reviews_Controller
|
* @extends WC_REST_Product_Reviews_Controller
|
||||||
*/
|
*/
|
||||||
class WC_Admin_REST_Product_Reviews_Controller extends WC_REST_Product_Reviews_Controller {
|
class WC_Admin_REST_Product_Reviews_Controller extends WC_REST_Product_Reviews_Controller {
|
||||||
|
/**
|
||||||
|
* Endpoint namespace.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare links for the request.
|
* Prepare links for the request.
|
||||||
|
|
|
@ -17,6 +17,13 @@ defined( 'ABSPATH' ) || exit;
|
||||||
*/
|
*/
|
||||||
class WC_Admin_REST_Products_Controller extends WC_REST_Products_Controller {
|
class WC_Admin_REST_Products_Controller extends WC_REST_Products_Controller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoint namespace.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds properties that can be embed via ?_embed=1.
|
* Adds properties that can be embed via ?_embed=1.
|
||||||
*
|
*
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_Reports_Categories_Controller extends WC_Admin_REST_Reports_
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_Reports_Controller extends WC_REST_Reports_Controller {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_Reports_Coupons_Controller extends WC_REST_Reports_Controlle
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_Reports_Coupons_Stats_Controller extends WC_REST_Reports_Con
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_Reports_Customers_Controller extends WC_REST_Reports_Control
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_Reports_Downloads_Controller extends WC_REST_Reports_Control
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_Reports_Downloads_Files_Controller extends WC_REST_Reports_C
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_Reports_Downloads_Stats_Controller extends WC_REST_Reports_C
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_Reports_Orders_Stats_Controller extends WC_Admin_REST_Report
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_Reports_Performance_Indicators_Controller extends WC_REST_Re
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
@ -53,7 +53,7 @@ class WC_Admin_REST_Reports_Performance_Indicators_Controller extends WC_REST_Re
|
||||||
public function get_allowed_stats() {
|
public function get_allowed_stats() {
|
||||||
global $wp_rest_server;
|
global $wp_rest_server;
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'GET', '/wc/v3/reports' );
|
$request = new WP_REST_Request( 'GET', '/wc/v4/reports' );
|
||||||
$response = rest_do_request( $request );
|
$response = rest_do_request( $request );
|
||||||
$endpoints = $response->get_data();
|
$endpoints = $response->get_data();
|
||||||
$allowed_stats = array();
|
$allowed_stats = array();
|
||||||
|
@ -63,7 +63,7 @@ class WC_Admin_REST_Reports_Performance_Indicators_Controller extends WC_REST_Re
|
||||||
|
|
||||||
foreach ( $endpoints as $endpoint ) {
|
foreach ( $endpoints as $endpoint ) {
|
||||||
if ( '/stats' === substr( $endpoint['slug'], -6 ) ) {
|
if ( '/stats' === substr( $endpoint['slug'], -6 ) ) {
|
||||||
$request = new WP_REST_Request( 'OPTIONS', '/wc/v3/reports/' . $endpoint['slug'] );
|
$request = new WP_REST_Request( 'OPTIONS', '/wc/v4/reports/' . $endpoint['slug'] );
|
||||||
$response = rest_do_request( $request );
|
$response = rest_do_request( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$prefix = substr( $endpoint['slug'], 0, -6 );
|
$prefix = substr( $endpoint['slug'], 0, -6 );
|
||||||
|
@ -126,7 +126,7 @@ class WC_Admin_REST_Reports_Performance_Indicators_Controller extends WC_REST_Re
|
||||||
if ( ! empty( $stats_endpoints [ $endpoint ] ) ) {
|
if ( ! empty( $stats_endpoints [ $endpoint ] ) ) {
|
||||||
$request_url = $stats_endpoints [ $endpoint ];
|
$request_url = $stats_endpoints [ $endpoint ];
|
||||||
} else {
|
} else {
|
||||||
$request_url = '/wc/v3/reports/' . $endpoint . '/stats';
|
$request_url = '/wc/v4/reports/' . $endpoint . '/stats';
|
||||||
}
|
}
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'GET', $request_url );
|
$request = new WP_REST_Request( 'GET', $request_url );
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_Reports_Products_Controller extends WC_REST_Reports_Controll
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_Reports_Products_Stats_Controller extends WC_REST_Reports_Co
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_Reports_Revenue_Stats_Controller extends WC_REST_Reports_Con
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_Reports_Stock_Controller extends WC_REST_Reports_Controller
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_Reports_Taxes_Controller extends WC_REST_Reports_Controller
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_Reports_Taxes_Stats_Controller extends WC_REST_Reports_Contr
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_Reports_Variations_Controller extends WC_REST_Reports_Contro
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route base.
|
* Route base.
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_Admin_REST_System_Status_Tools_Controller extends WC_REST_System_Status
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'wc/v3';
|
protected $namespace = 'wc/v4';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of available tools for use in the system status section.
|
* A list of available tools for use in the system status section.
|
||||||
|
|
|
@ -155,10 +155,11 @@ class WC_Admin_Api_Init {
|
||||||
*/
|
*/
|
||||||
public function rest_api_init() {
|
public function rest_api_init() {
|
||||||
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-admin-notes-controller.php';
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-admin-notes-controller.php';
|
||||||
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-coupons-controller.php';
|
||||||
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-customers-controller.php';
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-customers-controller.php';
|
||||||
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-data-controller.php';
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-data-controller.php';
|
||||||
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-data-download-ips-controller.php';
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-data-download-ips-controller.php';
|
||||||
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-orders-stats-controller.php';
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-orders-controller.php';
|
||||||
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-products-controller.php';
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-products-controller.php';
|
||||||
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-product-reviews-controller.php';
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-product-reviews-controller.php';
|
||||||
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-controller.php';
|
require_once dirname( __FILE__ ) . '/api/class-wc-admin-rest-reports-controller.php';
|
||||||
|
@ -185,10 +186,11 @@ class WC_Admin_Api_Init {
|
||||||
'woocommerce_admin_rest_controllers',
|
'woocommerce_admin_rest_controllers',
|
||||||
array(
|
array(
|
||||||
'WC_Admin_REST_Admin_Notes_Controller',
|
'WC_Admin_REST_Admin_Notes_Controller',
|
||||||
|
'WC_Admin_REST_Coupons_Controller',
|
||||||
'WC_Admin_REST_Customers_Controller',
|
'WC_Admin_REST_Customers_Controller',
|
||||||
'WC_Admin_REST_Data_Controller',
|
'WC_Admin_REST_Data_Controller',
|
||||||
'WC_Admin_REST_Data_Download_Ips_Controller',
|
'WC_Admin_REST_Data_Download_Ips_Controller',
|
||||||
'WC_Admin_REST_Orders_Stats_Controller',
|
'WC_Admin_REST_Orders_Controller',
|
||||||
'WC_Admin_REST_Products_Controller',
|
'WC_Admin_REST_Products_Controller',
|
||||||
'WC_Admin_REST_Product_Reviews_Controller',
|
'WC_Admin_REST_Product_Reviews_Controller',
|
||||||
'WC_Admin_REST_Reports_Controller',
|
'WC_Admin_REST_Reports_Controller',
|
||||||
|
@ -227,112 +229,123 @@ class WC_Admin_Api_Init {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function filter_rest_endpoints( $endpoints ) {
|
public static function filter_rest_endpoints( $endpoints ) {
|
||||||
// Override GET /wc/v3/system_status/tools.
|
// Override GET /wc/v4/system_status/tools.
|
||||||
if ( isset( $endpoints['/wc/v3/system_status/tools'] )
|
if ( isset( $endpoints['/wc/v4/system_status/tools'] )
|
||||||
&& isset( $endpoints['/wc/v3/system_status/tools'][1] )
|
&& isset( $endpoints['/wc/v4/system_status/tools'][1] )
|
||||||
&& isset( $endpoints['/wc/v3/system_status/tools'][0] )
|
&& isset( $endpoints['/wc/v4/system_status/tools'][0] )
|
||||||
&& $endpoints['/wc/v3/system_status/tools'][1]['callback'][0] instanceof WC_Admin_REST_System_Status_Tools_Controller
|
&& $endpoints['/wc/v4/system_status/tools'][1]['callback'][0] instanceof WC_Admin_REST_System_Status_Tools_Controller
|
||||||
) {
|
) {
|
||||||
$endpoints['/wc/v3/system_status/tools'][0] = $endpoints['/wc/v3/system_status/tools'][1];
|
$endpoints['/wc/v4/system_status/tools'][0] = $endpoints['/wc/v4/system_status/tools'][1];
|
||||||
}
|
}
|
||||||
// // Override GET & PUT for /wc/v3/system_status/tools.
|
// // Override GET & PUT for /wc/v4/system_status/tools.
|
||||||
if ( isset( $endpoints['/wc/v3/system_status/tools/(?P<id>[\w-]+)'] )
|
if ( isset( $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'] )
|
||||||
&& isset( $endpoints['/wc/v3/system_status/tools/(?P<id>[\w-]+)'][3] )
|
&& isset( $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][3] )
|
||||||
&& isset( $endpoints['/wc/v3/system_status/tools/(?P<id>[\w-]+)'][2] )
|
&& isset( $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][2] )
|
||||||
&& $endpoints['/wc/v3/system_status/tools/(?P<id>[\w-]+)'][2]['callback'][0] instanceof WC_Admin_REST_System_Status_Tools_Controller
|
&& $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][2]['callback'][0] instanceof WC_Admin_REST_System_Status_Tools_Controller
|
||||||
&& $endpoints['/wc/v3/system_status/tools/(?P<id>[\w-]+)'][3]['callback'][0] instanceof WC_Admin_REST_System_Status_Tools_Controller
|
&& $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][3]['callback'][0] instanceof WC_Admin_REST_System_Status_Tools_Controller
|
||||||
) {
|
) {
|
||||||
$endpoints['/wc/v3/system_status/tools/(?P<id>[\w-]+)'][0] = $endpoints['/wc/v3/system_status/tools/(?P<id>[\w-]+)'][2];
|
$endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][0] = $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][2];
|
||||||
$endpoints['/wc/v3/system_status/tools/(?P<id>[\w-]+)'][1] = $endpoints['/wc/v3/system_status/tools/(?P<id>[\w-]+)'][3];
|
$endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][1] = $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][3];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override GET /wc/v3/reports.
|
// Override GET /wc/v4/reports.
|
||||||
if ( isset( $endpoints['/wc/v3/reports'] )
|
if ( isset( $endpoints['/wc/v4/reports'] )
|
||||||
&& isset( $endpoints['/wc/v3/reports'][1] )
|
&& isset( $endpoints['/wc/v4/reports'][1] )
|
||||||
&& isset( $endpoints['/wc/v3/reports'][0] )
|
&& isset( $endpoints['/wc/v4/reports'][0] )
|
||||||
&& $endpoints['/wc/v3/reports'][1]['callback'][0] instanceof WC_Admin_REST_Reports_Controller
|
&& $endpoints['/wc/v4/reports'][1]['callback'][0] instanceof WC_Admin_REST_Reports_Controller
|
||||||
) {
|
) {
|
||||||
$endpoints['/wc/v3/reports'][0] = $endpoints['/wc/v3/reports'][1];
|
$endpoints['/wc/v4/reports'][0] = $endpoints['/wc/v4/reports'][1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override /wc/v3/customers.
|
// Override /wc/v4/coupons.
|
||||||
if ( isset( $endpoints['/wc/v3/customers'] )
|
if ( isset( $endpoints['/wc/v4/coupons'] )
|
||||||
&& isset( $endpoints['/wc/v3/customers'][3] )
|
&& isset( $endpoints['/wc/v4/coupons'][3] )
|
||||||
&& isset( $endpoints['/wc/v3/customers'][2] )
|
&& isset( $endpoints['/wc/v4/coupons'][2] )
|
||||||
&& $endpoints['/wc/v3/customers'][2]['callback'][0] instanceof WC_Admin_REST_Customers_Controller
|
&& $endpoints['/wc/v4/coupons'][2]['callback'][0] instanceof WC_Admin_REST_Orders_Controller
|
||||||
&& $endpoints['/wc/v3/customers'][3]['callback'][0] instanceof WC_Admin_REST_Customers_Controller
|
&& $endpoints['/wc/v4/coupons'][3]['callback'][0] instanceof WC_Admin_REST_Orders_Controller
|
||||||
) {
|
) {
|
||||||
$endpoints['/wc/v3/customers'][0] = $endpoints['/wc/v3/customers'][2];
|
$endpoints['/wc/v4/coupons'][0] = $endpoints['/wc/v4/coupons'][2];
|
||||||
$endpoints['/wc/v3/customers'][1] = $endpoints['/wc/v3/customers'][3];
|
$endpoints['/wc/v4/coupons'][1] = $endpoints['/wc/v4/coupons'][3];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override /wc/v3/orders/$id.
|
// Override /wc/v4/customers.
|
||||||
if ( isset( $endpoints['/wc/v3/orders/(?P<id>[\d]+)'] )
|
if ( isset( $endpoints['/wc/v4/customers'] )
|
||||||
&& isset( $endpoints['/wc/v3/orders/(?P<id>[\d]+)'][5] )
|
&& isset( $endpoints['/wc/v4/customers'][3] )
|
||||||
&& isset( $endpoints['/wc/v3/orders/(?P<id>[\d]+)'][4] )
|
&& isset( $endpoints['/wc/v4/customers'][2] )
|
||||||
&& isset( $endpoints['/wc/v3/orders/(?P<id>[\d]+)'][3] )
|
&& $endpoints['/wc/v4/customers'][2]['callback'][0] instanceof WC_Admin_REST_Customers_Controller
|
||||||
&& $endpoints['/wc/v3/orders/(?P<id>[\d]+)'][3]['callback'][0] instanceof WC_Admin_REST_Orders_Stats_Controller
|
&& $endpoints['/wc/v4/customers'][3]['callback'][0] instanceof WC_Admin_REST_Customers_Controller
|
||||||
&& $endpoints['/wc/v3/orders/(?P<id>[\d]+)'][4]['callback'][0] instanceof WC_Admin_REST_Orders_Stats_Controller
|
|
||||||
&& $endpoints['/wc/v3/orders/(?P<id>[\d]+)'][5]['callback'][0] instanceof WC_Admin_REST_Orders_Stats_Controller
|
|
||||||
) {
|
) {
|
||||||
$endpoints['/wc/v3/orders/(?P<id>[\d]+)'][0] = $endpoints['/wc/v3/orders/(?P<id>[\d]+)'][3];
|
$endpoints['/wc/v4/customers'][0] = $endpoints['/wc/v4/customers'][2];
|
||||||
$endpoints['/wc/v3/orders/(?P<id>[\d]+)'][1] = $endpoints['/wc/v3/orders/(?P<id>[\d]+)'][4];
|
$endpoints['/wc/v4/customers'][1] = $endpoints['/wc/v4/customers'][3];
|
||||||
$endpoints['/wc/v3/orders/(?P<id>[\d]+)'][2] = $endpoints['/wc/v3/orders/(?P<id>[\d]+)'][5];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override /wc/v3orders.
|
// Override /wc/v4/orders/$id.
|
||||||
if ( isset( $endpoints['/wc/v3/orders'] )
|
if ( isset( $endpoints['/wc/v4/orders/(?P<id>[\d]+)'] )
|
||||||
&& isset( $endpoints['/wc/v3/orders'][3] )
|
&& isset( $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][5] )
|
||||||
&& isset( $endpoints['/wc/v3/orders'][2] )
|
&& isset( $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][4] )
|
||||||
&& $endpoints['/wc/v3/orders'][2]['callback'][0] instanceof WC_Admin_REST_Orders_Stats_Controller
|
&& isset( $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][3] )
|
||||||
&& $endpoints['/wc/v3/orders'][3]['callback'][0] instanceof WC_Admin_REST_Orders_Stats_Controller
|
&& $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][3]['callback'][0] instanceof WC_Admin_REST_Orders_Controller
|
||||||
|
&& $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][4]['callback'][0] instanceof WC_Admin_REST_Orders_Controller
|
||||||
|
&& $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][5]['callback'][0] instanceof WC_Admin_REST_Orders_Controller
|
||||||
) {
|
) {
|
||||||
$endpoints['/wc/v3/orders'][0] = $endpoints['/wc/v3/orders'][2];
|
$endpoints['/wc/v4/orders/(?P<id>[\d]+)'][0] = $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][3];
|
||||||
$endpoints['/wc/v3/orders'][1] = $endpoints['/wc/v3/orders'][3];
|
$endpoints['/wc/v4/orders/(?P<id>[\d]+)'][1] = $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][4];
|
||||||
|
$endpoints['/wc/v4/orders/(?P<id>[\d]+)'][2] = $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][5];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override /wc/v3/data.
|
// Override /wc/v4/orders.
|
||||||
if ( isset( $endpoints['/wc/v3/data'] )
|
if ( isset( $endpoints['/wc/v4/orders'] )
|
||||||
&& isset( $endpoints['/wc/v3/data'][1] )
|
&& isset( $endpoints['/wc/v4/orders'][3] )
|
||||||
&& $endpoints['/wc/v3/data'][1]['callback'][0] instanceof WC_Admin_REST_Data_Controller
|
&& isset( $endpoints['/wc/v4/orders'][2] )
|
||||||
|
&& $endpoints['/wc/v4/orders'][2]['callback'][0] instanceof WC_Admin_REST_Orders_Controller
|
||||||
|
&& $endpoints['/wc/v4/orders'][3]['callback'][0] instanceof WC_Admin_REST_Orders_Controller
|
||||||
) {
|
) {
|
||||||
$endpoints['/wc/v3/data'][0] = $endpoints['/wc/v3/data'][1];
|
$endpoints['/wc/v4/orders'][0] = $endpoints['/wc/v4/orders'][2];
|
||||||
|
$endpoints['/wc/v4/orders'][1] = $endpoints['/wc/v4/orders'][3];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override /wc/v3/products.
|
// Override /wc/v4/data.
|
||||||
if ( isset( $endpoints['/wc/v3/products'] )
|
if ( isset( $endpoints['/wc/v4/data'] )
|
||||||
&& isset( $endpoints['/wc/v3/products'][3] )
|
&& isset( $endpoints['/wc/v4/data'][1] )
|
||||||
&& isset( $endpoints['/wc/v3/products'][2] )
|
&& $endpoints['/wc/v4/data'][1]['callback'][0] instanceof WC_Admin_REST_Data_Controller
|
||||||
&& $endpoints['/wc/v3/products'][2]['callback'][0] instanceof WC_Admin_REST_Products_Controller
|
|
||||||
&& $endpoints['/wc/v3/products'][3]['callback'][0] instanceof WC_Admin_REST_Products_Controller
|
|
||||||
) {
|
) {
|
||||||
$endpoints['/wc/v3/products'][0] = $endpoints['/wc/v3/products'][2];
|
$endpoints['/wc/v4/data'][0] = $endpoints['/wc/v4/data'][1];
|
||||||
$endpoints['/wc/v3/products'][1] = $endpoints['/wc/v3/products'][3];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override /wc/v3/products/$id.
|
// Override /wc/v4/products.
|
||||||
if ( isset( $endpoints['/wc/v3/products/(?P<id>[\d]+)'] )
|
if ( isset( $endpoints['/wc/v4/products'] )
|
||||||
&& isset( $endpoints['/wc/v3/products/(?P<id>[\d]+)'][5] )
|
&& isset( $endpoints['/wc/v4/products'][3] )
|
||||||
&& isset( $endpoints['/wc/v3/products/(?P<id>[\d]+)'][4] )
|
&& isset( $endpoints['/wc/v4/products'][2] )
|
||||||
&& isset( $endpoints['/wc/v3/products/(?P<id>[\d]+)'][3] )
|
&& $endpoints['/wc/v4/products'][2]['callback'][0] instanceof WC_Admin_REST_Products_Controller
|
||||||
&& $endpoints['/wc/v3/products/(?P<id>[\d]+)'][3]['callback'][0] instanceof WC_Admin_REST_Products_Controller
|
&& $endpoints['/wc/v4/products'][3]['callback'][0] instanceof WC_Admin_REST_Products_Controller
|
||||||
&& $endpoints['/wc/v3/products/(?P<id>[\d]+)'][4]['callback'][0] instanceof WC_Admin_REST_Products_Controller
|
|
||||||
&& $endpoints['/wc/v3/products/(?P<id>[\d]+)'][5]['callback'][0] instanceof WC_Admin_REST_Products_Controller
|
|
||||||
) {
|
) {
|
||||||
$endpoints['/wc/v3/products/(?P<id>[\d]+)'][0] = $endpoints['/wc/v3/products/(?P<id>[\d]+)'][3];
|
$endpoints['/wc/v4/products'][0] = $endpoints['/wc/v4/products'][2];
|
||||||
$endpoints['/wc/v3/products/(?P<id>[\d]+)'][1] = $endpoints['/wc/v3/products/(?P<id>[\d]+)'][4];
|
$endpoints['/wc/v4/products'][1] = $endpoints['/wc/v4/products'][3];
|
||||||
$endpoints['/wc/v3/products/(?P<id>[\d]+)'][2] = $endpoints['/wc/v3/products/(?P<id>[\d]+)'][5];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override /wc/v3/products/reviews.
|
// Override /wc/v4/products/$id.
|
||||||
if ( isset( $endpoints['/wc/v3/products/reviews'] )
|
if ( isset( $endpoints['/wc/v4/products/(?P<id>[\d]+)'] )
|
||||||
&& isset( $endpoints['/wc/v3/products/reviews'][3] )
|
&& isset( $endpoints['/wc/v4/products/(?P<id>[\d]+)'][5] )
|
||||||
&& isset( $endpoints['/wc/v3/products/reviews'][2] )
|
&& isset( $endpoints['/wc/v4/products/(?P<id>[\d]+)'][4] )
|
||||||
&& $endpoints['/wc/v3/products/reviews'][2]['callback'][0] instanceof WC_Admin_REST_Product_Reviews_Controller
|
&& isset( $endpoints['/wc/v4/products/(?P<id>[\d]+)'][3] )
|
||||||
&& $endpoints['/wc/v3/products/reviews'][3]['callback'][0] instanceof WC_Admin_REST_Product_Reviews_Controller
|
&& $endpoints['/wc/v4/products/(?P<id>[\d]+)'][3]['callback'][0] instanceof WC_Admin_REST_Products_Controller
|
||||||
|
&& $endpoints['/wc/v4/products/(?P<id>[\d]+)'][4]['callback'][0] instanceof WC_Admin_REST_Products_Controller
|
||||||
|
&& $endpoints['/wc/v4/products/(?P<id>[\d]+)'][5]['callback'][0] instanceof WC_Admin_REST_Products_Controller
|
||||||
) {
|
) {
|
||||||
$endpoints['/wc/v3/products/reviews'][0] = $endpoints['/wc/v3/products/reviews'][2];
|
$endpoints['/wc/v4/products/(?P<id>[\d]+)'][0] = $endpoints['/wc/v4/products/(?P<id>[\d]+)'][3];
|
||||||
$endpoints['/wc/v3/products/reviews'][1] = $endpoints['/wc/v3/products/reviews'][3];
|
$endpoints['/wc/v4/products/(?P<id>[\d]+)'][1] = $endpoints['/wc/v4/products/(?P<id>[\d]+)'][4];
|
||||||
|
$endpoints['/wc/v4/products/(?P<id>[\d]+)'][2] = $endpoints['/wc/v4/products/(?P<id>[\d]+)'][5];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Override /wc/v4/products/reviews.
|
||||||
|
if ( isset( $endpoints['/wc/v4/products/reviews'] )
|
||||||
|
&& isset( $endpoints['/wc/v4/products/reviews'][3] )
|
||||||
|
&& isset( $endpoints['/wc/v4/products/reviews'][2] )
|
||||||
|
&& $endpoints['/wc/v4/products/reviews'][2]['callback'][0] instanceof WC_Admin_REST_Product_Reviews_Controller
|
||||||
|
&& $endpoints['/wc/v4/products/reviews'][3]['callback'][0] instanceof WC_Admin_REST_Product_Reviews_Controller
|
||||||
|
) {
|
||||||
|
$endpoints['/wc/v4/products/reviews'][0] = $endpoints['/wc/v4/products/reviews'][2];
|
||||||
|
$endpoints['/wc/v4/products/reviews'][1] = $endpoints['/wc/v4/products/reviews'][3];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $endpoints;
|
return $endpoints;
|
||||||
|
|
|
@ -42,7 +42,7 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp
|
||||||
protected $report_columns = array(
|
protected $report_columns = array(
|
||||||
'order_id' => 'order_id',
|
'order_id' => 'order_id',
|
||||||
'date_created' => 'date_created',
|
'date_created' => 'date_created',
|
||||||
'status' => 'status',
|
'status' => 'REPLACE(status, "wc-", "") as status',
|
||||||
'customer_id' => 'customer_id',
|
'customer_id' => 'customer_id',
|
||||||
'net_total' => 'net_total',
|
'net_total' => 'net_total',
|
||||||
'num_items_sold' => 'num_items_sold',
|
'num_items_sold' => 'num_items_sold',
|
||||||
|
@ -240,6 +240,7 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp
|
||||||
$mapped_orders = $this->map_array_by_key( $orders_data, 'order_id' );
|
$mapped_orders = $this->map_array_by_key( $orders_data, 'order_id' );
|
||||||
$products = $this->get_products_by_order_ids( array_keys( $mapped_orders ) );
|
$products = $this->get_products_by_order_ids( array_keys( $mapped_orders ) );
|
||||||
$mapped_products = $this->map_array_by_key( $products, 'product_id' );
|
$mapped_products = $this->map_array_by_key( $products, 'product_id' );
|
||||||
|
$coupons = $this->get_coupons_by_order_ids( array_keys( $mapped_orders ) );
|
||||||
$product_categories = $this->get_product_categories_by_product_ids( array_keys( $mapped_products ) );
|
$product_categories = $this->get_product_categories_by_product_ids( array_keys( $mapped_products ) );
|
||||||
|
|
||||||
$mapped_data = array();
|
$mapped_data = array();
|
||||||
|
@ -252,6 +253,7 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp
|
||||||
$mapped_data[ $product['order_id'] ]['products'][] = array(
|
$mapped_data[ $product['order_id'] ]['products'][] = array(
|
||||||
'id' => $product['product_id'],
|
'id' => $product['product_id'],
|
||||||
'name' => $product['product_name'],
|
'name' => $product['product_name'],
|
||||||
|
'quantity' => $product['product_quantity'],
|
||||||
);
|
);
|
||||||
$mapped_data[ $product['order_id'] ]['categories'] = array_unique(
|
$mapped_data[ $product['order_id'] ]['categories'] = array_unique(
|
||||||
array_merge(
|
array_merge(
|
||||||
|
@ -261,8 +263,24 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ( $coupons as $coupon ) {
|
||||||
|
if ( ! isset( $mapped_data[ $coupon['order_id'] ] ) ) {
|
||||||
|
$mapped_data[ $product['order_id'] ]['coupons'] = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mapped_data[ $coupon['order_id'] ]['coupons'][] = array(
|
||||||
|
'id' => $coupon['coupon_id'],
|
||||||
|
'code' => wc_format_coupon_code( $coupon['coupon_code'] ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ( $orders_data as $key => $order_data ) {
|
foreach ( $orders_data as $key => $order_data ) {
|
||||||
$orders_data[ $key ]['extended_info'] = $mapped_data[ $order_data['order_id'] ];
|
$defaults = array(
|
||||||
|
'products' => array(),
|
||||||
|
'categories' => array(),
|
||||||
|
'coupons' => array(),
|
||||||
|
);
|
||||||
|
$orders_data[ $key ]['extended_info'] = isset( $mapped_data[ $order_data['order_id'] ] ) ? array_merge( $defaults, $mapped_data[ $order_data['order_id'] ] ) : $defaults;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +300,7 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get product Ids, names, and categories from order IDs.
|
* Get product IDs, names, and quantity from order IDs.
|
||||||
*
|
*
|
||||||
* @param array $order_ids Array of order IDs.
|
* @param array $order_ids Array of order IDs.
|
||||||
* @return array
|
* @return array
|
||||||
|
@ -293,7 +311,7 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp
|
||||||
$included_order_ids = implode( ',', $order_ids );
|
$included_order_ids = implode( ',', $order_ids );
|
||||||
|
|
||||||
$products = $wpdb->get_results(
|
$products = $wpdb->get_results(
|
||||||
"SELECT order_id, ID as product_id, post_title as product_name
|
"SELECT order_id, ID as product_id, post_title as product_name, product_qty as product_quantity
|
||||||
FROM {$wpdb->prefix}posts
|
FROM {$wpdb->prefix}posts
|
||||||
JOIN {$order_product_lookup_table} ON {$order_product_lookup_table}.product_id = {$wpdb->prefix}posts.ID
|
JOIN {$order_product_lookup_table} ON {$order_product_lookup_table}.product_id = {$wpdb->prefix}posts.ID
|
||||||
WHERE
|
WHERE
|
||||||
|
@ -305,6 +323,30 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp
|
||||||
return $products;
|
return $products;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get coupon information from order IDs.
|
||||||
|
*
|
||||||
|
* @param array $order_ids Array of order IDs.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function get_coupons_by_order_ids( $order_ids ) {
|
||||||
|
global $wpdb;
|
||||||
|
$order_coupon_lookup_table = $wpdb->prefix . 'wc_order_coupon_lookup';
|
||||||
|
$included_order_ids = implode( ',', $order_ids );
|
||||||
|
|
||||||
|
$coupons = $wpdb->get_results(
|
||||||
|
"SELECT order_id, coupon_id, post_title as coupon_code
|
||||||
|
FROM {$wpdb->prefix}posts
|
||||||
|
JOIN {$order_coupon_lookup_table} ON {$order_coupon_lookup_table}.coupon_id = {$wpdb->prefix}posts.ID
|
||||||
|
WHERE
|
||||||
|
order_id IN ({$included_order_ids})
|
||||||
|
",
|
||||||
|
ARRAY_A
|
||||||
|
); // WPCS: cache ok, DB call ok, unprepared SQL ok.
|
||||||
|
|
||||||
|
return $coupons;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get product categories by array of product IDs
|
* Get product categories by array of product IDs
|
||||||
*
|
*
|
||||||
|
|
|
@ -153,7 +153,7 @@ function wc_admin_print_script_settings() {
|
||||||
}
|
}
|
||||||
|
|
||||||
$preload_data_endpoints = array(
|
$preload_data_endpoints = array(
|
||||||
'countries' => '/wc/v3/data/countries',
|
'countries' => '/wc/v4/data/countries',
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( function_exists( 'gutenberg_preload_api_request' ) ) {
|
if ( function_exists( 'gutenberg_preload_api_request' ) ) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ export default {
|
||||||
};
|
};
|
||||||
payload = stringifyQuery( query );
|
payload = stringifyQuery( query );
|
||||||
}
|
}
|
||||||
return apiFetch( { path: `/wc/v3/coupons${ payload }` } );
|
return apiFetch( { path: `/wc/v4/coupons${ payload }` } );
|
||||||
},
|
},
|
||||||
isDebounced: true,
|
isDebounced: true,
|
||||||
getOptionKeywords( coupon ) {
|
getOptionKeywords( coupon ) {
|
||||||
|
|
|
@ -34,7 +34,7 @@ export default {
|
||||||
};
|
};
|
||||||
payload = stringifyQuery( query );
|
payload = stringifyQuery( query );
|
||||||
}
|
}
|
||||||
return apiFetch( { path: `/wc/v3/customers${ payload }` } );
|
return apiFetch( { path: `/wc/v4/customers${ payload }` } );
|
||||||
},
|
},
|
||||||
isDebounced: true,
|
isDebounced: true,
|
||||||
getOptionKeywords( customer ) {
|
getOptionKeywords( customer ) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ export default {
|
||||||
match,
|
match,
|
||||||
};
|
};
|
||||||
payload = stringifyQuery( query );
|
payload = stringifyQuery( query );
|
||||||
return apiFetch( { path: `/wc/v3/data/download-ips${ payload }` } );
|
return apiFetch( { path: `/wc/v4/data/download-ips${ payload }` } );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isDebounced: true,
|
isDebounced: true,
|
||||||
|
|
|
@ -32,7 +32,7 @@ export default {
|
||||||
};
|
};
|
||||||
payload = stringifyQuery( query );
|
payload = stringifyQuery( query );
|
||||||
}
|
}
|
||||||
return apiFetch( { path: `/wc/v3/customers${ payload }` } );
|
return apiFetch( { path: `/wc/v4/customers${ payload }` } );
|
||||||
},
|
},
|
||||||
isDebounced: true,
|
isDebounced: true,
|
||||||
getOptionKeywords( customer ) {
|
getOptionKeywords( customer ) {
|
||||||
|
|
|
@ -38,7 +38,7 @@ export default {
|
||||||
per_page: 10,
|
per_page: 10,
|
||||||
};
|
};
|
||||||
payload = stringifyQuery( query );
|
payload = stringifyQuery( query );
|
||||||
return apiFetch( { path: `/wc/v3/orders${ payload }` } );
|
return apiFetch( { path: `/wc/v4/orders${ payload }` } );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isDebounced: true,
|
isDebounced: true,
|
||||||
|
|
|
@ -34,7 +34,7 @@ export default {
|
||||||
};
|
};
|
||||||
payload = stringifyQuery( query );
|
payload = stringifyQuery( query );
|
||||||
}
|
}
|
||||||
return apiFetch( { path: `/wc/v3/products${ payload }` } );
|
return apiFetch( { path: `/wc/v4/products${ payload }` } );
|
||||||
},
|
},
|
||||||
isDebounced: true,
|
isDebounced: true,
|
||||||
getOptionKeywords( product ) {
|
getOptionKeywords( product ) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ export default {
|
||||||
};
|
};
|
||||||
payload = stringifyQuery( query );
|
payload = stringifyQuery( query );
|
||||||
}
|
}
|
||||||
return apiFetch( { path: `/wc/v3/taxes${ payload }` } );
|
return apiFetch( { path: `/wc/v4/taxes${ payload }` } );
|
||||||
},
|
},
|
||||||
isDebounced: true,
|
isDebounced: true,
|
||||||
getOptionKeywords( tax ) {
|
getOptionKeywords( tax ) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ export default {
|
||||||
};
|
};
|
||||||
payload = stringifyQuery( query );
|
payload = stringifyQuery( query );
|
||||||
}
|
}
|
||||||
return apiFetch( { path: `/wc/v3/customers${ payload }` } );
|
return apiFetch( { path: `/wc/v4/customers${ payload }` } );
|
||||||
},
|
},
|
||||||
isDebounced: true,
|
isDebounced: true,
|
||||||
getOptionKeywords( customer ) {
|
getOptionKeywords( customer ) {
|
||||||
|
|
|
@ -52,7 +52,7 @@ export default {
|
||||||
if ( ! product || product.includes( ',' ) ) {
|
if ( ! product || product.includes( ',' ) ) {
|
||||||
console.warn( 'Invalid product id supplied to Variations autocompleter' );
|
console.warn( 'Invalid product id supplied to Variations autocompleter' );
|
||||||
}
|
}
|
||||||
return apiFetch( { path: `/wc/v3/products/${ product }/variations${ payload }` } );
|
return apiFetch( { path: `/wc/v4/products/${ product }/variations${ payload }` } );
|
||||||
},
|
},
|
||||||
isDebounced: true,
|
isDebounced: true,
|
||||||
getOptionKeywords( variation ) {
|
getOptionKeywords( variation ) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ class WC_Tests_API_Admin_Notes extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/admin/notes';
|
protected $endpoint = '/wc/v4/admin/notes';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test admin notes data. Called before every test.
|
* Setup test admin notes data. Called before every test.
|
||||||
|
|
|
@ -15,7 +15,7 @@ class WC_Tests_API_Data extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/data';
|
protected $endpoint = '/wc/v4/data';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test data. Called before every test.
|
* Setup test data. Called before every test.
|
||||||
|
|
|
@ -15,7 +15,7 @@ class WC_Tests_API_Orders extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/orders';
|
protected $endpoint = '/wc/v4/orders';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test data. Called before every test.
|
* Setup test data. Called before every test.
|
||||||
|
|
|
@ -15,7 +15,7 @@ class WC_Tests_API_Product_Reviews extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/products/reviews';
|
protected $endpoint = '/wc/v4/products/reviews';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test data. Called before every test.
|
* Setup test data. Called before every test.
|
||||||
|
@ -38,7 +38,7 @@ class WC_Tests_API_Product_Reviews extends WC_REST_Unit_Test_Case {
|
||||||
$product = WC_Helper_Product::create_simple_product();
|
$product = WC_Helper_Product::create_simple_product();
|
||||||
WC_Helper_Product::create_product_review( $product->get_id() );
|
WC_Helper_Product::create_product_review( $product->get_id() );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'GET', '/wc/v3/products/reviews' );
|
$request = new WP_REST_Request( 'GET', '/wc/v4/products/reviews' );
|
||||||
|
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
|
@ -15,7 +15,7 @@ class WC_Tests_API_Products extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/products';
|
protected $endpoint = '/wc/v4/products';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test data. Called before every test.
|
* Setup test data. Called before every test.
|
||||||
|
@ -36,7 +36,7 @@ class WC_Tests_API_Products extends WC_REST_Unit_Test_Case {
|
||||||
public function test_product_schema() {
|
public function test_product_schema() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
$product = WC_Helper_Product::create_simple_product();
|
$product = WC_Helper_Product::create_simple_product();
|
||||||
$request = new WP_REST_Request( 'OPTIONS', '/wc/v3/products/' . $product->get_id() );
|
$request = new WP_REST_Request( 'OPTIONS', '/wc/v4/products/' . $product->get_id() );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$properties = $data['schema']['properties'];
|
$properties = $data['schema']['properties'];
|
||||||
|
|
|
@ -16,7 +16,7 @@ class WC_Tests_API_Reports_Categories extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/reports/categories';
|
protected $endpoint = '/wc/v4/reports/categories';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test reports categories data.
|
* Setup test reports categories data.
|
||||||
|
|
|
@ -15,7 +15,7 @@ class WC_Tests_API_Reports_Coupons_Stats extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/reports/coupons/stats';
|
protected $endpoint = '/wc/v4/reports/coupons/stats';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test reports products stats data.
|
* Setup test reports products stats data.
|
||||||
|
|
|
@ -15,7 +15,7 @@ class WC_Tests_API_Reports_Coupons extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/reports/coupons';
|
protected $endpoint = '/wc/v4/reports/coupons';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test reports products data.
|
* Setup test reports products data.
|
||||||
|
|
|
@ -18,7 +18,7 @@ class WC_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/reports/customers';
|
protected $endpoint = '/wc/v4/reports/customers';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test reports products data.
|
* Setup test reports products data.
|
||||||
|
|
|
@ -15,7 +15,7 @@ class WC_Tests_API_Reports_Downloads_Stats extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/reports/downloads/stats';
|
protected $endpoint = '/wc/v4/reports/downloads/stats';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test reports downloads data.
|
* Setup test reports downloads data.
|
||||||
|
|
|
@ -15,7 +15,7 @@ class WC_Tests_API_Reports_Downloads extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/reports/downloads';
|
protected $endpoint = '/wc/v4/reports/downloads';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test reports downloads data.
|
* Setup test reports downloads data.
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
* @package WooCommerce\Tests\API
|
* @package WooCommerce\Tests\API
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class WC_Tests_API_Reports_Orders_Stats
|
||||||
|
*/
|
||||||
class WC_Tests_API_Reports_Orders_Stats extends WC_REST_Unit_Test_Case {
|
class WC_Tests_API_Reports_Orders_Stats extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,7 +16,7 @@ class WC_Tests_API_Reports_Orders_Stats extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/reports/orders/stats';
|
protected $endpoint = '/wc/v4/reports/orders/stats';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test reports orders data.
|
* Setup test reports orders data.
|
||||||
|
|
|
@ -15,7 +15,7 @@ class WC_Tests_API_Reports_Performance_Indicators extends WC_REST_Unit_Test_Case
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/reports/performance-indicators';
|
protected $endpoint = '/wc/v4/reports/performance-indicators';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup tests.
|
* Setup tests.
|
||||||
|
|
|
@ -16,7 +16,7 @@ class WC_Tests_API_Reports_Products_Stats extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/reports/products/stats';
|
protected $endpoint = '/wc/v4/reports/products/stats';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test reports products stats data.
|
* Setup test reports products stats data.
|
||||||
|
|
|
@ -19,7 +19,7 @@ class WC_Tests_API_Reports_Products extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/reports/products';
|
protected $endpoint = '/wc/v4/reports/products';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test reports products data.
|
* Setup test reports products data.
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
* @package WooCommerce\Tests\API
|
* @package WooCommerce\Tests\API
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class WC_Tests_API_Reports_Revenue_Stats
|
||||||
|
*/
|
||||||
class WC_Tests_API_Reports_Revenue_Stats extends WC_REST_Unit_Test_Case {
|
class WC_Tests_API_Reports_Revenue_Stats extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,8 +16,13 @@ class WC_Tests_API_Reports_Revenue_Stats extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/reports/revenue/stats';
|
protected $endpoint = '/wc/v4/reports/revenue/stats';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Orders
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
protected $orders = array();
|
protected $orders = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
* @package WooCommerce\Tests\API
|
* @package WooCommerce\Tests\API
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class WC_Tests_API_Reports_Stock
|
||||||
|
*/
|
||||||
class WC_Tests_API_Reports_Stock extends WC_REST_Unit_Test_Case {
|
class WC_Tests_API_Reports_Stock extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,7 +16,7 @@ class WC_Tests_API_Reports_Stock extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/reports/stock';
|
protected $endpoint = '/wc/v4/reports/stock';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test reports stock data.
|
* Setup test reports stock data.
|
||||||
|
|
|
@ -16,7 +16,7 @@ class WC_Tests_API_Reports_Taxes_Stats extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/reports/taxes/stats';
|
protected $endpoint = '/wc/v4/reports/taxes/stats';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test reports taxes data.
|
* Setup test reports taxes data.
|
||||||
|
|
|
@ -16,7 +16,7 @@ class WC_Tests_API_Reports_Taxes extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/reports/taxes';
|
protected $endpoint = '/wc/v4/reports/taxes';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test reports taxes data.
|
* Setup test reports taxes data.
|
||||||
|
|
|
@ -16,7 +16,7 @@ class WC_Tests_API_Reports_Variations extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $endpoint = '/wc/v3/reports/variations';
|
protected $endpoint = '/wc/v4/reports/variations';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test reports products data.
|
* Setup test reports products data.
|
||||||
|
|
Loading…
Reference in New Issue