diff --git a/includes/api/class-product-controller.php b/includes/api/class-product-controller.php index a342777449..3027c2ea61 100644 --- a/includes/api/class-product-controller.php +++ b/includes/api/class-product-controller.php @@ -141,6 +141,11 @@ public function register_routes() { 'type' => 'integer', 'default' => 8 ), + 'page' => array( + 'description' => __( 'Number of page number' ), + 'type' => 'integer', + 'default' => 1 + ), 'seller_id' => array( 'description' => __( 'Top rated product for specific vendor', 'dokan-lite' ), 'type' => 'integer', @@ -159,6 +164,11 @@ public function register_routes() { 'type' => 'integer', 'default' => 8 ), + 'page' => array( + 'description' => __( 'Number of page number' ), + 'type' => 'integer', + 'default' => 1 + ), 'seller_id' => array( 'description' => __( 'Top rated product for specific vendor', 'dokan-lite' ), 'type' => 'integer', @@ -177,6 +187,11 @@ public function register_routes() { 'type' => 'integer', 'default' => 8 ), + 'page' => array( + 'description' => __( 'Number of page number' ), + 'type' => 'integer', + 'default' => 1 + ), 'seller_id' => array( 'description' => __( 'Top rated product for specific vendor', 'dokan-lite' ), 'type' => 'integer', @@ -195,6 +210,11 @@ public function register_routes() { 'type' => 'integer', 'default' => 8 ), + 'page' => array( + 'description' => __( 'Number of page number' ), + 'type' => 'integer', + 'default' => 1 + ), 'seller_id' => array( 'description' => __( 'Top rated product for specific vendor', 'dokan-lite' ), 'type' => 'integer', @@ -426,7 +446,7 @@ public function get_related_product( $request ) { * @return void */ public function get_top_rated_product( $request ) { - $result = dokan_get_top_rated_products( $request['per_page'], $request['seller_id'] ); + $result = dokan_get_top_rated_products( $request['per_page'], $request['seller_id'], $request['page'] ); $data = array(); $response = array(); @@ -439,6 +459,7 @@ public function get_top_rated_product( $request ) { } $response = rest_ensure_response( $data_objects ); + $response = $this->format_collection_response( $response, $request, $result->found_posts ); } return $response; @@ -452,7 +473,7 @@ public function get_top_rated_product( $request ) { * @return array */ public function get_best_selling_product( $request ) { - $result = dokan_get_best_selling_products( $request['per_page'], $request['seller_id'] ); + $result = dokan_get_best_selling_products( $request['per_page'], $request['seller_id'], $request['page'] ); $data = array(); $response = array(); @@ -465,6 +486,7 @@ public function get_best_selling_product( $request ) { } $response = rest_ensure_response( $data_objects ); + $response = $this->format_collection_response( $response, $request, $result->found_posts ); } return $response; @@ -478,7 +500,7 @@ public function get_best_selling_product( $request ) { * @return array */ public function get_featured_product( $request ) { - $result = dokan_get_featured_products( $request['per_page'], $request['seller_id'] ); + $result = dokan_get_featured_products( $request['per_page'], $request['seller_id'], $request['page'] ); $data = array(); $response = array(); @@ -491,6 +513,7 @@ public function get_featured_product( $request ) { } $response = rest_ensure_response( $data_objects ); + $response = $this->format_collection_response( $response, $request, $result->found_posts ); } return $response; @@ -503,9 +526,9 @@ public function get_featured_product( $request ) { * @return array */ public function get_latest_product( $request ) { - $result = dokan_get_latest_products( $request['per_page'], $request['seller_id'] ); - $data = array(); - $response = array(); + $result = dokan_get_latest_products( $request['per_page'], $request['seller_id'], $request['page'] ); + $data = array(); + $response = array(); if ( $result->posts ) { $objects = array_map( array( $this, 'get_object' ), $result->posts ); @@ -516,6 +539,7 @@ public function get_latest_product( $request ) { } $response = rest_ensure_response( $data_objects ); + $response = $this->format_collection_response( $response, $request, $result->found_posts ); } return $response; diff --git a/includes/wc-functions.php b/includes/wc-functions.php index 59d647899d..e24dbe2233 100755 --- a/includes/wc-functions.php +++ b/includes/wc-functions.php @@ -518,10 +518,11 @@ function dokan_seller_displayname( $display_name ) { * @param int $per_page * @return \WP_Query */ -function dokan_get_featured_products( $per_page = 9, $seller_id = '' ) { +function dokan_get_featured_products( $per_page = 9, $seller_id = '', $page = 1 ) { $args = array( 'posts_per_page' => $per_page, + 'paged' => $page, 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'tax_query' => array( @@ -544,10 +545,11 @@ function dokan_get_featured_products( $per_page = 9, $seller_id = '' ) { * @param int $per_page * @return \WP_Query */ -function dokan_get_latest_products( $per_page = 9, $seller_id = '' ) { +function dokan_get_latest_products( $per_page = 9, $seller_id = '', $page = 1 ) { $args = array( 'posts_per_page' => $per_page, + 'paged' => $page, 'post_status' => 'publish', 'orderby' => 'publish_date', 'ignore_sticky_posts' => 1, @@ -568,13 +570,14 @@ function dokan_get_latest_products( $per_page = 9, $seller_id = '' ) { * @param int $per_page * @return \WP_Query */ -function dokan_get_best_selling_products( $per_page = 8, $seller_id = '' ) { +function dokan_get_best_selling_products( $per_page = 8, $seller_id = '', $page = 1 ) { $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $per_page, + 'paged' => $page ); if ( ! empty( $seller_id ) ) { @@ -612,13 +615,14 @@ function check_more_seller_product_tab() { * @param int $per_page * @return \WP_Query */ -function dokan_get_top_rated_products( $per_page = 8, $seller_id = '' ) { +function dokan_get_top_rated_products( $per_page = 8, $seller_id = '', $page = 1 ) { $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $per_page, + 'paged' => $page ); if ( ! empty( $seller_id ) ) {