From b5dd089d34eef5114437e8c1bb08a83ef79c1883 Mon Sep 17 00:00:00 2001 From: osman sufy Date: Wed, 1 Jan 2025 12:54:23 +0600 Subject: [PATCH 1/3] update: support include & exclude support in dokan product --- includes/REST/ProductControllerV2.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/includes/REST/ProductControllerV2.php b/includes/REST/ProductControllerV2.php index 60d21506a9..043714e1c8 100644 --- a/includes/REST/ProductControllerV2.php +++ b/includes/REST/ProductControllerV2.php @@ -39,7 +39,6 @@ public function register_routes() { [ 'methods' => WP_REST_Server::READABLE, 'callback' => [ $this, 'get_items' ], - 'args' => $this->get_product_collection_params(), 'permission_callback' => [ $this, 'get_product_permissions_check' ], ], 'schema' => [ $this, 'get_item_schema' ], @@ -119,7 +118,7 @@ private function set_chosen_categories( $response ) { * * @return array Query parameters. */ - public function get_product_collection_params() { + public function get_collection_params() { $params = parent::get_collection_params(); $params['author'] = array( @@ -177,6 +176,24 @@ public function get_product_collection_params() { 'validate_callback' => 'rest_validate_request_arg', 'required' => false, ); + $params['include'] = array( + 'description' => __( 'Limit result set to specific ids.', 'dokan-lite' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', + ), + 'default' => array(), + 'sanitize_callback' => 'wp_parse_id_list', + ); + $params['exclude'] = array( + 'description' => __( 'Ensure result set excludes specific IDs.', 'dokan-lite' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', + ), + 'default' => array(), + 'sanitize_callback' => 'wp_parse_id_list', + ); return $params; } From 9413ddfddfc404c524fbdb73d7109bed835d4c35 Mon Sep 17 00:00:00 2001 From: Osman Goni Sufy <47870515+osmansufy@users.noreply.github.com> Date: Wed, 1 Jan 2025 15:53:12 +0600 Subject: [PATCH 2/3] Update: raplace hardcode pagination & sorting --- includes/REST/ProductControllerV2.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/REST/ProductControllerV2.php b/includes/REST/ProductControllerV2.php index 043714e1c8..61a37dc6da 100644 --- a/includes/REST/ProductControllerV2.php +++ b/includes/REST/ProductControllerV2.php @@ -231,13 +231,13 @@ public function get_product_filter_by_data() { protected function prepare_objects_query( $request ) { $args = parent::prepare_objects_query( $request ); - $args = array_merge( + $args = array_merge( $args, array( - 'posts_per_page' => 10, - 'paged' => 1, + 'posts_per_page' => isset( $request['per_page'] ) ? $request['per_page'] : 10, + 'paged' => isset( $request['page'] ) ? $request['page'] : 1, 'author' => dokan_get_current_user_id(), - 'orderby' => 'post_date', + 'orderby' => isset( $request['orderby'] ) ? $request['orderby'] : 'date', 'post_type' => 'product', 'date_query' => [], 'tax_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query From 8fd4352ca544f0c15a6273c4bdcc241171ea47dc Mon Sep 17 00:00:00 2001 From: osman sufy Date: Mon, 13 Jan 2025 08:35:59 +0600 Subject: [PATCH 3/3] fix: php cs issue --- includes/REST/ProductControllerV2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/REST/ProductControllerV2.php b/includes/REST/ProductControllerV2.php index 61a37dc6da..a5ecf7b1db 100644 --- a/includes/REST/ProductControllerV2.php +++ b/includes/REST/ProductControllerV2.php @@ -231,7 +231,7 @@ public function get_product_filter_by_data() { protected function prepare_objects_query( $request ) { $args = parent::prepare_objects_query( $request ); - $args = array_merge( + $args = array_merge( $args, array( 'posts_per_page' => isset( $request['per_page'] ) ? $request['per_page'] : 10,