feat: Add support for categories in product import and export (#8375)
* feat: Add support for product categories on export and import * fix: Make the rest of the import workflow async as well
This commit is contained in:
@@ -62,16 +62,26 @@ const normalizeProductForExport = (product: HttpTypes.AdminProduct): object => {
|
||||
{}
|
||||
)
|
||||
|
||||
const flattenedCategories = product.categories?.reduce(
|
||||
(acc: Record<string, string>, category, idx) => {
|
||||
acc[beautifyKey(`product_category_${idx + 1}`)] = category.id
|
||||
return acc
|
||||
},
|
||||
{}
|
||||
)
|
||||
|
||||
const res = {
|
||||
...prefixFields(product, "product"),
|
||||
...flattenedImages,
|
||||
...flattenedTags,
|
||||
...flattenedSalesChannels,
|
||||
...flattenedCategories,
|
||||
} as any
|
||||
|
||||
delete res["Product Images"]
|
||||
delete res["Product Tags"]
|
||||
delete res["Product Sales Channels"]
|
||||
delete res["Product Categories"]
|
||||
|
||||
// We can decide if we want the metadata in the export and how that would look like
|
||||
delete res["Product Metadata"]
|
||||
|
||||
@@ -123,6 +123,14 @@ const normalizeProductForImport = (
|
||||
return
|
||||
}
|
||||
|
||||
if (normalizedKey.startsWith("product_category_")) {
|
||||
response["categories"] = [
|
||||
...(response["categories"] || []),
|
||||
{ id: normalizedValue },
|
||||
]
|
||||
return
|
||||
}
|
||||
|
||||
if (
|
||||
normalizedKey.startsWith("product_") &&
|
||||
!productFieldsToOmit.has(normalizedKey)
|
||||
|
||||
@@ -46,9 +46,12 @@ export const importProductsWorkflow = createWorkflow(
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
notifyOnFailureStep(failureNotification)
|
||||
|
||||
batchProductsWorkflow.runAsStep({ input: batchRequest })
|
||||
batchProductsWorkflow
|
||||
.runAsStep({ input: batchRequest })
|
||||
.config({ async: true, backgroundExecution: true })
|
||||
|
||||
const notifications = transform({ input }, (data) => {
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user