From 8547a750aa7f7c281b068b84755313936b67e403 Mon Sep 17 00:00:00 2001 From: Renzo van Hootegem Date: Fri, 15 Nov 2024 14:38:49 +0100 Subject: [PATCH 1/2] Prevent errors by returning string instead of array --- .../mesh/algoliaHitToMagentoProduct.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/algolia-products/mesh/algoliaHitToMagentoProduct.ts b/packages/algolia-products/mesh/algoliaHitToMagentoProduct.ts index 5fb284bacb..6ec97f57b3 100644 --- a/packages/algolia-products/mesh/algoliaHitToMagentoProduct.ts +++ b/packages/algolia-products/mesh/algoliaHitToMagentoProduct.ts @@ -147,6 +147,15 @@ export function algoliaHitToMagentoProduct( ...rest } = additionalProperties + // Some custom attributes are returned as array while they need to be a string. Flatten those arrays + const flattenedCustomAttributes = {} + for (const [key, value] of Object.entries(rest)) { + if (value !== null && Array.isArray(value) && value?.length > 0) { + flattenedCustomAttributes[key] = value.toString() + delete rest[key] + } + } + return { redirect_code: 0, __typename: algoliaTypeToTypename[type_id as keyof typeof algoliaTypeToTypename], @@ -187,5 +196,6 @@ export function algoliaHitToMagentoProduct( url_key: algoliaUrlToUrlKey(url, storeConfig?.base_link_url), url_suffix: storeConfig?.product_url_suffix, ...rest, + ...flattenedCustomAttributes, } } From 743e7e275c8f0bfe32a5240c08eed92120085cc0 Mon Sep 17 00:00:00 2001 From: Paul Hachmang Date: Mon, 18 Nov 2024 13:06:03 +0100 Subject: [PATCH 2/2] Create witty-apes-rescue.md --- .changeset/witty-apes-rescue.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/witty-apes-rescue.md diff --git a/.changeset/witty-apes-rescue.md b/.changeset/witty-apes-rescue.md new file mode 100644 index 0000000000..33c1bbc7c1 --- /dev/null +++ b/.changeset/witty-apes-rescue.md @@ -0,0 +1,5 @@ +--- +"@graphcommerce/algolia-products": patch +--- + +Prevent errors by returning string instead of array