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:
parent
ab797e8237
commit
dcc4e60dda
|
@ -106,10 +106,14 @@ const withReviews = ( OriginalComponent ) => {
|
||||||
offset: reviewsToSkip,
|
offset: reviewsToSkip,
|
||||||
};
|
};
|
||||||
|
|
||||||
if ( categoryIds && categoryIds.length ) {
|
if ( categoryIds ) {
|
||||||
args.category_id = Array.isArray( categoryIds )
|
const categories = Array.isArray( categoryIds )
|
||||||
? categoryIds.join( ',' )
|
? categoryIds
|
||||||
: categoryIds;
|
: JSON.parse( categoryIds );
|
||||||
|
|
||||||
|
args.category_id = Array.isArray( categories )
|
||||||
|
? categories.join( ',' )
|
||||||
|
: categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( productId ) {
|
if ( productId ) {
|
||||||
|
|
Loading…
Reference in New Issue