From a6c11b0ca8bd19f6edc05b1588a2a3861939988d Mon Sep 17 00:00:00 2001 From: Hussain Mousavi Date: Thu, 14 Sep 2023 15:41:58 +0330 Subject: [PATCH] Product review And Variation Fix Store Api --- src/StoreApi/Routes/V1/ProductReviews.php | 1 + src/StoreApi/Schemas/V1/ProductReviewSchema.php | 1 + src/StoreApi/Schemas/V1/ProductSchema.php | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/src/StoreApi/Routes/V1/ProductReviews.php b/src/StoreApi/Routes/V1/ProductReviews.php index 82c9610e66d..d6446f80183 100644 --- a/src/StoreApi/Routes/V1/ProductReviews.php +++ b/src/StoreApi/Routes/V1/ProductReviews.php @@ -63,6 +63,7 @@ protected function get_route_response( \WP_REST_Request $request ) { 'order' => $request['order'], 'number' => $request['per_page'], 'post__in' => $request['product_id'], + 'parent' => (int) $request['parent'], ); /** diff --git a/src/StoreApi/Schemas/V1/ProductReviewSchema.php b/src/StoreApi/Schemas/V1/ProductReviewSchema.php index 75932239a77..300efb8497a 100644 --- a/src/StoreApi/Schemas/V1/ProductReviewSchema.php +++ b/src/StoreApi/Schemas/V1/ProductReviewSchema.php @@ -175,6 +175,7 @@ public function get_item_response( $review ) { 'rating' => $rating, 'verified' => wc_review_is_from_verified_owner( $review->comment_ID ), 'reviewer_avatar_urls' => rest_get_avatar_urls( $review->comment_author_email ), + 'parent_id'=> (int) $review->comment_parent, ]; if ( 'view' === $context ) { diff --git a/src/StoreApi/Schemas/V1/ProductSchema.php b/src/StoreApi/Schemas/V1/ProductSchema.php index 9d7935b9d7b..99dd3f5a7e7 100644 --- a/src/StoreApi/Schemas/V1/ProductSchema.php +++ b/src/StoreApi/Schemas/V1/ProductSchema.php @@ -651,8 +651,15 @@ function( $values, $data ) use ( $default_variation_meta_keys ) { } } + $variation = wc_get_product($variation_id); $variations[] = (object) [ 'id' => $variation_id, + 'images' => $this->get_images($variation), + 'prices' => (object) $this->prepare_product_price_response($variation), + 'is_purchasable' => $variation->is_purchasable(), + 'is_in_stock' => $variation->is_in_stock(), + 'is_on_backorder' => 'onbackorder' === $variation->get_stock_status(), + 'low_stock_remaining' => $this->get_low_stock_remaining( $variation ), 'attributes' => array_values( $attribute_data ), ]; }