diff --git a/includes/model/class-product.php b/includes/model/class-product.php index 6c3033040..ef5cbb4ae 100644 --- a/includes/model/class-product.php +++ b/includes/model/class-product.php @@ -105,7 +105,7 @@ protected function init() { return ! empty( $this->wc_data->get_slug() ) ? $this->wc_data->get_slug() : null; }, 'name' => function() { - return ! empty( $this->wc_data->get_name() ) ? $this->wc_data->get_name() : null; + return ! empty( $this->wc_data->get_name() ) ? html_entity_decode( $this->wc_data->get_name() ) : null; }, 'date' => function() { return ! empty( $this->wc_data ) ? $this->wc_data->get_date_created() : null; diff --git a/includes/mutation/class-review-update.php b/includes/mutation/class-review-update.php index fd14a57a5..15d411704 100644 --- a/includes/mutation/class-review-update.php +++ b/includes/mutation/class-review-update.php @@ -72,17 +72,30 @@ public static function mutate_and_get_payload() { // Set comment type to "review". $input['type'] = 'review'; - $resolver = CommentUpdate::mutate_and_get_payload(); + $skip = array( + 'type' => 'review', + 'id' => 1, + 'rating' => 1, + 'clientMutationId' => 1, + ); - $payload = $resolver( $input, $context, $info ); + $payload = array(); + $id_parts = ! empty( $input['id'] ) ? Relay::fromGlobalId( $input['id'] ) : null; + $payload['id'] = isset( $id_parts['id'] ) && absint( $id_parts['id'] ) ? absint( $id_parts['id'] ) : null; + + if ( empty( $payload['id'] ) ) { + throw new UserError( __( 'The Review could not be updated', 'wp-graphql-woocommerce' ) ); + } + + if ( array_intersect_key( $input, $skip ) !== $input ) { + $resolver = CommentUpdate::mutate_and_get_payload(); + + $payload = $resolver( $input, $context, $info ); + } // Check if product rating needs updating. if ( ! empty( $payload['id'] ) && isset( $input['rating'] ) ) { - $success = update_comment_meta( $payload['id'], 'rating', $input['rating'] ); - - if ( ! $success ) { - throw UserError( __( 'Failed to update review rating', 'wp-graphql-woocommerce' ) ); - } + update_comment_meta( $payload['id'], 'rating', $input['rating'] ); } return $payload; diff --git a/includes/mutation/class-review-write.php b/includes/mutation/class-review-write.php index 1fbfa848c..6b8af4f57 100644 --- a/includes/mutation/class-review-write.php +++ b/includes/mutation/class-review-write.php @@ -101,6 +101,9 @@ public static function mutate_and_get_payload() { $resolver = CommentCreate::mutate_and_get_payload(); $payload = $resolver( $input, $context, $info ); + if ( is_a( $payload, UserError::class ) ) { + throw $payload; + } // Set product rating upon successful creation of the review. if ( $payload['success'] ) {