Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Parse categories coming from the back-end as a json array
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
albarin committed May 3, 2022
1 parent 4a131a5 commit eba150d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions assets/js/base/hocs/with-reviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down

0 comments on commit eba150d

Please sign in to comment.