Parse categories coming from the back-end as a json array (https://github.com/woocommerce/woocommerce-blocks/pull/6358)

* 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.

* Only parse category ids if not undefined
This commit is contained in:
Alba Rincón 2022-05-03 16:09:20 +02:00 committed by GitHub
parent ab797e8237
commit dcc4e60dda
1 changed files with 8 additions and 4 deletions

View File

@ -106,10 +106,14 @@ const withReviews = ( OriginalComponent ) => {
offset: reviewsToSkip,
};
if ( categoryIds && categoryIds.length ) {
args.category_id = Array.isArray( categoryIds )
? categoryIds.join( ',' )
: categoryIds;
if ( categoryIds ) {
const categories = Array.isArray( categoryIds )
? categoryIds
: JSON.parse( categoryIds );
args.category_id = Array.isArray( categories )
? categories.join( ',' )
: categories;
}
if ( productId ) {