Skip to content

Commit

Permalink
fix: check if dokan pro exists
Browse files Browse the repository at this point in the history
  • Loading branch information
kapilpaul committed Nov 20, 2020
1 parent 002e0fe commit 3c91ab5
Showing 1 changed file with 38 additions and 36 deletions.
74 changes: 38 additions & 36 deletions includes/REST/StoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,49 +486,51 @@ public function get_store_reviews( $request ) {
return new WP_Error( 'no_store_found', __( 'No store found', 'dokan-lite' ), [ 'status' => 404 ] );
}

if ( ! dokan_pro()->module->is_active( 'store_reviews' ) ) {
$args = [
'post_type' => 'dokan_store_reviews',
'meta_key' => 'store_id', //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
'meta_value' => $store_id, //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
'post_status' => 'publish',
'posts_per_page' => (int) $request['per_page'],
'paged' => (int) $request['page'],
'author__not_in' => [ get_current_user_id(), $store_id ],
];
if ( dokan()->is_pro_exists() ) {
if ( dokan_pro()->module->is_active( 'store_reviews' ) ) {
$args = [
'post_type' => 'dokan_store_reviews',
'meta_key' => 'store_id', //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
'meta_value' => $store_id, //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
'post_status' => 'publish',
'posts_per_page' => (int) $request['per_page'],
'paged' => (int) $request['page'],
'author__not_in' => [ get_current_user_id(), $store_id ],
];

$query = new WP_Query( $args );
$query = new WP_Query( $args );

if ( empty( $query->posts ) ) {
return new WP_Error( 'no_reviews_found', __( 'No reviews found', 'dokan-lite' ), [ 'status' => 404 ] );
}
if ( empty( $query->posts ) ) {
return new WP_Error( 'no_reviews_found', __( 'No reviews found', 'dokan-lite' ), [ 'status' => 404 ] );
}

$data = [];
$data = [];

foreach ( $query->posts as $post ) {
$data[] = $this->prepare_reviews_for_response( $post, $request );
}
foreach ( $query->posts as $post ) {
$data[] = $this->prepare_reviews_for_response( $post, $request );
}

$total_count = $query->found_posts;
} else {
$dokan_template_reviews = dokan_pro()->review;
$post_type = 'product';
$limit = (int) $params['per_page'];
$paged = (int) ( $params['page'] - 1 ) * $params['per_page'];
$status = '1';
$comments = $dokan_template_reviews->comment_query( $store_id, $post_type, $limit, $status, $paged );

if ( empty( $comments ) ) {
return new WP_Error( 'no_reviews_found', __( 'No reviews found', 'dokan-lite' ), [ 'status' => 404 ] );
}
$total_count = $query->found_posts;
} else {
$dokan_template_reviews = dokan_pro()->review;
$post_type = 'product';
$limit = (int) $params['per_page'];
$paged = (int) ( $params['page'] - 1 ) * $params['per_page'];
$status = '1';
$comments = $dokan_template_reviews->comment_query( $store_id, $post_type, $limit, $status, $paged );

if ( empty( $comments ) ) {
return new WP_Error( 'no_reviews_found', __( 'No reviews found', 'dokan-lite' ), [ 'status' => 404 ] );
}

$data = [];
$data = [];

foreach ( $comments as $comment ) {
$data[] = $this->prepare_reviews_for_response( $comment, $request );
}
foreach ( $comments as $comment ) {
$data[] = $this->prepare_reviews_for_response( $comment, $request );
}

$total_count = $this->get_total_review_count( $store_id, $post_type, $status );
$total_count = $this->get_total_review_count( $store_id, $post_type, $status );
}
}

$response = rest_ensure_response( $data );
Expand Down Expand Up @@ -594,7 +596,7 @@ public function prepare_item_for_response( $store, $request, $additional_fields
* @return WP_REST_Response $response Response data.
*/
public function prepare_reviews_for_response( $item, $request, $additional_fields = [] ) {
if ( ! dokan_pro()->module->is_active( 'store_reviews' ) ) {
if ( dokan()->is_pro_exists() && dokan_pro()->module->is_active( 'store_reviews' ) ) {
$user = get_user_by( 'id', $item->post_author );
$user_gravatar = get_avatar_url( $user->user_email );

Expand Down

0 comments on commit 3c91ab5

Please sign in to comment.