Skip to content

Commit

Permalink
fix: Don't remove pricing if no variant is passed to update
Browse files Browse the repository at this point in the history
  • Loading branch information
sradevski committed Aug 2, 2024
1 parent 4d99cd5 commit fae7c5e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 39 deletions.

This file was deleted.

34 changes: 31 additions & 3 deletions packages/core/core-flows/src/product/workflows/update-products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
useRemoteQueryStep,
} from "../../common"
import { upsertVariantPricesWorkflow } from "./upsert-variant-prices"
import { getVariantIdsForProductsStep } from "../steps/get-variant-ids-for-products"

type UpdateProductsStepInputSelector = {
selector: ProductTypes.FilterableProductProps
Expand Down Expand Up @@ -214,7 +213,36 @@ export const updateProductsWorkflowId = "update-products"
export const updateProductsWorkflow = createWorkflow(
updateProductsWorkflowId,
(input: WorkflowData<WorkflowInput>) => {
const previousVariantIds = getVariantIdsForProductsStep(input)
// We only get the variant ids of products that are updating the variants and prices.
const variantIdsSelector = transform({ input }, (data) => {
if ("products" in data.input) {
return {
filters: {
id: data.input.products
.filter((p) => p.variants && p.variants.some((v) => v.prices))
.map((p) => p.id),
},
}
}

return {
filter:
data.input.update.variants &&
data.input.update.variants.some((v) => !!v.prices)
? data.input.selector
: { id: [] },
}
})
const previousProductsWithVariants = useRemoteQueryStep({
entry_point: "product",
fields: ["variants.id"],
variables: variantIdsSelector,
}).config({ name: "get-previous-products-variants-step" })

const previousVariantIds = transform(
{ previousProductsWithVariants },
(data) => data.previousProductsWithVariants.map((p) => p.variants.id)
)

const toUpdateInput = transform({ input }, prepareUpdateProductInput)
const updatedProducts = updateProductsStep(toUpdateInput)
Expand All @@ -237,7 +265,7 @@ export const updateProductsWorkflow = createWorkflow(
entry_point: "product_sales_channel",
fields: ["product_id", "sales_channel_id"],
variables: { filters: { product_id: updatedProductIds } },
})
}).config({ name: "get-current-sales-channel-links-step" })

const toDeleteSalesChannelLinks = transform(
{ currentSalesChannelLinks },
Expand Down

0 comments on commit fae7c5e

Please sign in to comment.