Skip to content

Commit

Permalink
feat: add page parameter for pagination (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
saimonh3 authored and sabbir1991 committed Jan 4, 2019
1 parent 0fab721 commit 9b83cce
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
36 changes: 30 additions & 6 deletions includes/api/class-product-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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();

Expand All @@ -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;
Expand All @@ -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();

Expand All @@ -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;
Expand All @@ -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();

Expand All @@ -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;
Expand All @@ -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 );
Expand All @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions includes/wc-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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 ) ) {
Expand Down Expand Up @@ -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 ) ) {
Expand Down

0 comments on commit 9b83cce

Please sign in to comment.