From 604c182a20d64e83187b8f6a35b218b2fcf58ae2 Mon Sep 17 00:00:00 2001 From: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> Date: Mon, 21 Oct 2024 09:55:50 +0200 Subject: [PATCH] fix(core-flows): Actually emit event in update products workflow (#9682) --- .../src/product/workflows/update-products.ts | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/core/core-flows/src/product/workflows/update-products.ts b/packages/core/core-flows/src/product/workflows/update-products.ts index 559dbfe873..a9bcf84ed1 100644 --- a/packages/core/core-flows/src/product/workflows/update-products.ts +++ b/packages/core/core-flows/src/product/workflows/update-products.ts @@ -81,7 +81,8 @@ function prepareUpdateProductInput({ } } -function updateProductIds({ +// This helper finds the IDs of products that have associated sales channels. +function findProductsWithSalesChannels({ updatedProducts, input, }: { @@ -252,10 +253,6 @@ export const updateProductsWorkflow = createWorkflow( const toUpdateInput = transform({ input }, prepareUpdateProductInput) const updatedProducts = updateProductsStep(toUpdateInput) - const updatedProductIds = transform( - { updatedProducts, input }, - updateProductIds - ) const salesChannelLinks = transform( { input, updatedProducts }, @@ -267,10 +264,15 @@ export const updateProductsWorkflow = createWorkflow( prepareVariantPrices ) + const productsWithSalesChannels = transform( + { updatedProducts, input }, + findProductsWithSalesChannels + ) + const currentSalesChannelLinks = useRemoteQueryStep({ entry_point: "product_sales_channel", fields: ["product_id", "sales_channel_id"], - variables: { filters: { product_id: updatedProductIds } }, + variables: { filters: { product_id: productsWithSalesChannels } }, }).config({ name: "get-current-sales-channel-links-step" }) const toDeleteSalesChannelLinks = transform( @@ -285,10 +287,10 @@ export const updateProductsWorkflow = createWorkflow( dismissRemoteLinkStep(toDeleteSalesChannelLinks) const productIdEvents = transform( - { updatedProductIds }, - ({ updatedProductIds }) => { - return updatedProductIds?.map((id) => { - return { id } + { updatedProducts }, + ({ updatedProducts }) => { + return updatedProducts?.map((p) => { + return { id: p.id } }) } )