chore: append variants to created products on workflow (#7560)
This commit is contained in:
@@ -74,7 +74,7 @@ export const createProductVariantsWorkflow = createWorkflow(
|
||||
(data) => {
|
||||
return data.variantAndPriceSets.map((variantAndPriceSet) => ({
|
||||
...variantAndPriceSet.variant,
|
||||
...variantAndPriceSet.price_set,
|
||||
prices: variantAndPriceSet?.price_set?.prices || [],
|
||||
}))
|
||||
}
|
||||
)
|
||||
|
||||
@@ -73,8 +73,25 @@ export const createProductsWorkflow = createWorkflow(
|
||||
}
|
||||
})
|
||||
|
||||
createProductVariantsWorkflow.runAsStep(variantsInput)
|
||||
const createdVariants =
|
||||
createProductVariantsWorkflow.runAsStep(variantsInput)
|
||||
|
||||
return createdProducts
|
||||
return transform({ createdVariants, input, createdProducts }, (data) => {
|
||||
const variantMap: Record<string, ProductTypes.ProductVariantDTO[]> = {}
|
||||
|
||||
for (const variant of data.createdVariants) {
|
||||
const array = variantMap[variant.product_id!] || []
|
||||
|
||||
array.push(variant)
|
||||
|
||||
variantMap[variant.product_id!] = array
|
||||
}
|
||||
|
||||
for (const product of data.createdProducts) {
|
||||
product.variants = variantMap[product.id] || []
|
||||
}
|
||||
|
||||
return data.createdProducts
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user