From 9f547afa579164458c26041a351b1e9cf473eb50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Tue, 3 May 2022 12:29:50 +0200 Subject: [PATCH 1/2] Parse categories coming from the back-end as a json array The category ids that come from php are in json array format (e.g. '[40,41]'), so it's necessary to parse them and convert them into a js array before processing them. Otherwise the api request will fail. --- assets/js/base/hocs/with-reviews.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/assets/js/base/hocs/with-reviews.js b/assets/js/base/hocs/with-reviews.js index 0c1a50fd882..68282b8ce75 100644 --- a/assets/js/base/hocs/with-reviews.js +++ b/assets/js/base/hocs/with-reviews.js @@ -106,10 +106,14 @@ const withReviews = ( OriginalComponent ) => { offset: reviewsToSkip, }; - if ( categoryIds && categoryIds.length ) { - args.category_id = Array.isArray( categoryIds ) - ? categoryIds.join( ',' ) - : categoryIds; + const categories = Array.isArray( categoryIds ) + ? categoryIds + : JSON.parse( categoryIds ); + + if ( categories && categories.length ) { + args.category_id = Array.isArray( categories ) + ? categories.join( ',' ) + : categories; } if ( productId ) { From 32040b0568c6d9a08c557c0b86ef5c86448b9a3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Tue, 3 May 2022 14:52:13 +0200 Subject: [PATCH 2/2] Only parse category ids if not undefined --- assets/js/base/hocs/with-reviews.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/assets/js/base/hocs/with-reviews.js b/assets/js/base/hocs/with-reviews.js index 68282b8ce75..16de44cc9bc 100644 --- a/assets/js/base/hocs/with-reviews.js +++ b/assets/js/base/hocs/with-reviews.js @@ -106,11 +106,11 @@ const withReviews = ( OriginalComponent ) => { offset: reviewsToSkip, }; - const categories = Array.isArray( categoryIds ) - ? categoryIds - : JSON.parse( categoryIds ); + if ( categoryIds ) { + const categories = Array.isArray( categoryIds ) + ? categoryIds + : JSON.parse( categoryIds ); - if ( categories && categories.length ) { args.category_id = Array.isArray( categories ) ? categories.join( ',' ) : categories;