Merge pull request woocommerce/woocommerce-admin#1907 from woocommerce/fix/1615-order-number-filter
Support Sequential Order Numbers in Downloads Report order number filter
This commit is contained in:
commit
a3fdd72ba5
|
@ -30,10 +30,10 @@ class WC_Admin_REST_Orders_Controller extends WC_REST_Orders_Controller {
|
||||||
*/
|
*/
|
||||||
public function get_collection_params() {
|
public function get_collection_params() {
|
||||||
$params = parent::get_collection_params();
|
$params = parent::get_collection_params();
|
||||||
|
// This needs to remain a string to support extensions that filter Order Number.
|
||||||
$params['number'] = array(
|
$params['number'] = array(
|
||||||
'description' => __( 'Limit result set to orders matching part of an order number.', 'woocommerce-admin' ),
|
'description' => __( 'Limit result set to orders matching part of an order number.', 'woocommerce-admin' ),
|
||||||
'type' => 'integer',
|
'type' => 'string',
|
||||||
'sanitize_callback' => 'absint',
|
|
||||||
'validate_callback' => 'rest_validate_request_arg',
|
'validate_callback' => 'rest_validate_request_arg',
|
||||||
);
|
);
|
||||||
return $params;
|
return $params;
|
||||||
|
@ -51,15 +51,22 @@ class WC_Admin_REST_Orders_Controller extends WC_REST_Orders_Controller {
|
||||||
|
|
||||||
// Search by partial order number.
|
// Search by partial order number.
|
||||||
if ( ! empty( $request['number'] ) ) {
|
if ( ! empty( $request['number'] ) ) {
|
||||||
$order_ids = $wpdb->get_col(
|
$partial_number = trim( $request['number'] );
|
||||||
|
$limit = intval( $args['posts_per_page'] );
|
||||||
|
$order_ids = $wpdb->get_col(
|
||||||
$wpdb->prepare(
|
$wpdb->prepare(
|
||||||
"SELECT ID FROM {$wpdb->prefix}posts WHERE post_type = 'shop_order' AND ID LIKE %s",
|
"SELECT ID
|
||||||
intval( $request['number'] ) . '%'
|
FROM {$wpdb->prefix}posts
|
||||||
|
WHERE post_type = 'shop_order'
|
||||||
|
AND ID LIKE %s
|
||||||
|
LIMIT %d",
|
||||||
|
$wpdb->esc_like( absint( $partial_number ) ) . '%',
|
||||||
|
$limit
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Force WP_Query return empty if don't found any order.
|
// Force WP_Query return empty if don't found any order.
|
||||||
$order_ids = ! empty( $order_ids ) ? $order_ids : array( 0 );
|
$order_ids = empty( $order_ids ) ? array( 0 ) : $order_ids;
|
||||||
$args['post__in'] = $order_ids;
|
$args['post__in'] = $order_ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import apiFetch from '@wordpress/api-fetch';
|
import apiFetch from '@wordpress/api-fetch';
|
||||||
import { isNaN } from 'lodash';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WooCommerce dependencies
|
* WooCommerce dependencies
|
||||||
|
@ -24,18 +23,11 @@ import { computeSuggestionMatch } from './utils';
|
||||||
export default {
|
export default {
|
||||||
name: 'orders',
|
name: 'orders',
|
||||||
className: 'woocommerce-search__order-result',
|
className: 'woocommerce-search__order-result',
|
||||||
inputType: 'number',
|
|
||||||
options( search ) {
|
options( search ) {
|
||||||
let payload = '';
|
let payload = '';
|
||||||
if ( search ) {
|
if ( search ) {
|
||||||
const number = parseInt( search );
|
|
||||||
|
|
||||||
if ( isNaN( number ) ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
number,
|
number: search,
|
||||||
per_page: 10,
|
per_page: 10,
|
||||||
};
|
};
|
||||||
payload = stringifyQuery( query );
|
payload = stringifyQuery( query );
|
||||||
|
|
|
@ -46,7 +46,7 @@ class WC_Tests_API_Orders extends WC_REST_Unit_Test_Case {
|
||||||
$request = new WP_REST_Request( 'GET', $this->endpoint );
|
$request = new WP_REST_Request( 'GET', $this->endpoint );
|
||||||
$request->set_query_params(
|
$request->set_query_params(
|
||||||
array(
|
array(
|
||||||
'number' => $order->get_id(),
|
'number' => (string) $order->get_id(),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue