Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/model/class-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 20 additions & 7 deletions includes/mutation/class-review-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using static access to class '\GraphQLRelay\Relay' in method 'mutate_and_get_payload'.

$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;
Expand Down
3 changes: 3 additions & 0 deletions includes/mutation/class-review-write.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) {
Expand Down