chore: append variants to created products on workflow (#7560)

This commit is contained in:
Riqwan Thamir
2024-05-30 22:23:43 +02:00
committed by GitHub
parent 6b86b1d531
commit 2d956931b3
2 changed files with 20 additions and 3 deletions

View File

@@ -74,7 +74,7 @@ export const createProductVariantsWorkflow = createWorkflow(
(data) => {
return data.variantAndPriceSets.map((variantAndPriceSet) => ({
...variantAndPriceSet.variant,
...variantAndPriceSet.price_set,
prices: variantAndPriceSet?.price_set?.prices || [],
}))
}
)

View File

@@ -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
})
}
)