Skip to content

Commit

Permalink
Fix, returns empty orders list in dokan rest api. (#2105)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aunshon authored Dec 27, 2023
1 parent 747d1fd commit c3ccbe2
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions includes/REST/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit c3ccbe2

Please sign in to comment.