From c3ccbe223bfa3dc98a20be45b501efba559ed417 Mon Sep 17 00:00:00 2001 From: Aunshon Date: Wed, 27 Dec 2023 15:35:13 +0600 Subject: [PATCH] Fix, returns empty orders list in dokan rest api. (#2105) --- includes/REST/OrderController.php | 35 +++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/includes/REST/OrderController.php b/includes/REST/OrderController.php index 7e78c4eb81..aab15a8768 100644 --- a/includes/REST/OrderController.php +++ b/includes/REST/OrderController.php @@ -1043,8 +1043,8 @@ public function get_item_schema() { ), 'customer_id' => array( 'description' => __( 'User ID who owns the order. 0 for guests.', 'dokan-lite' ), - 'type' => 'integer', - 'default' => 0, + 'type' => 'string', + 'default' => '', 'context' => array( 'view' ), ), 'search' => array( @@ -1745,6 +1745,28 @@ public function get_item_schema() { return $this->add_additional_fields_schema( $schema ); } + /** + * Validating the customer id to query orders. + * + * @since DOKAN_SINCE + * + * @param string $param + * @param WP_REST_Request $request + * @param string $key + * + * @return boolean|WP_Error + */ + public function rest_validate_customer_id( $param, $request, $key ) { + if ( is_numeric( $param ) || empty( $param ) ) { + return true; + } + + return new WP_Error( + 'rest_invalid_param', + __( 'The customer_id must be an integer, accepted value is 0 or any integer value', 'dokan-lite' ) + ); + } + /** * Retrieves the query params for the posts collection. * @@ -1782,10 +1804,11 @@ public function get_collection_params() { ); $query_params['customer_id'] = array( - 'required' => false, - 'default' => $schema_properties['customer_id']['default'], - 'description' => $schema_properties['customer_id']['description'], - 'type' => $schema_properties['customer_id']['type'], + 'required' => false, + 'default' => $schema_properties['customer_id']['default'], + 'description' => $schema_properties['customer_id']['description'], + 'type' => $schema_properties['customer_id']['type'], + 'validate_callback' => [ $this, 'rest_validate_customer_id' ], ); $query_params['search'] = array(