Skip to main content
This page lists the workflows that stage, resolve, apply, and record product changes. Import them from @mercurjs/core/workflows and run them with the Medusa container, for example confirmProductChangeWorkflow(container).run({ input }). Each section gives the workflow id, the input, the hooks, and the events.

Edit workflows

These workflows load the current product, diff your input against it, check that the author has no pending change on the product, and stage the result through stageProductChangeWorkflow. They return the staged ProductChangeDTO.

productEditUpdateProductWorkflow

Id product-edit-update-product. Stages an UPDATE action per changed product field, and a STATUS_CHANGE action when status differs. Hooks: validate with { input }, and productChangeCreated with { product_change, additional_data }.

productEditUpdateVariantsWorkflow

Id product-edit-update-variants. Stages VARIANT_ADD, VARIANT_UPDATE, and VARIANT_REMOVE actions. An update stages only the fields that differ, and manage_inventory is never staged. No hooks.

productEditUpdateAttributesWorkflow

Id product-edit-update-attributes. Stages ATTRIBUTE_ADD, ATTRIBUTE_UPDATE, and ATTRIBUTE_REMOVE actions, skipping entries that wouldn’t change the product. Hooks: validate with { input }, and productChangeCreated with { product_change, additional_data }.

productEditDeleteProductWorkflow

Id product-edit-delete-product. Stages a single PRODUCT_DELETE action. No hooks. On confirm, the product and its offers are deleted.

Staging and resolution workflows

These workflows create a change and move it through its statuses.

stageProductChangeWorkflow

Id stage-product-change. Creates one pending change with the given actions, emits product-change.created, then runs autoConfirmProductChangeWorkflow. It doesn’t check for an open change. No hooks. Returns the created ProductChangeDTO, without its actions.

createProductChangeWorkflow

Id create-product-change. Creates pending changes without actions, after checking that none of the products has a pending change from the same author. When the batch spans several authors, the check covers every pending change on those products. Hooks: validate with { input }, and productChangeCreated with { changes, additional_data }. Emits product-change.created per change.

autoConfirmProductChangeWorkflow

Id auto-confirm-product-change. Runs confirmProductChangeWorkflow when force is true or the product_request feature flag is off. Otherwise it does nothing.

confirmProductChangeWorkflow

Id confirm-product-change. Sets every change in ids to confirmed, runs applyProductChangeActionsWorkflow, and emits product-change.confirmed per change. Fails if any change is missing or not pending. Hooks: validate with { input }, and productChangeConfirmed with { ids, additional_data }.

rejectProductChangeWorkflow

Id reject-product-change. Sets one pending change to declined and emits product-change.declined. Hooks: validate with { input }, and productChangeRejected with { id, additional_data }.

cancelProductChangeWorkflow

Id cancel-product-change. Sets one pending change to canceled and emits product-change.canceled. Hooks: validate with { input }, and productChangeCanceled with { id, additional_data }.

Apply workflows

confirmProductChangeWorkflow runs these for you, so you rarely call them yourself.

applyProductChangeActionsWorkflow

Id apply-product-change-actions. Input { change_ids: string[] }. Loads the unapplied actions of the given changes, groups them by type, runs Medusa’s product and variant workflows, deletes the offers of deleted products, and marks the handled actions applied. No hooks, no events of its own.

applyProductAttributeChangeActionsWorkflow

Id apply-product-attribute-change-actions. Input { product_id, add, remove, update }. Runs createAndLinkProductAttributesToProductWorkflow when any array is non-empty. No hooks.

Audit workflows

These workflows record history that doesn’t need review.

recordProductAuditChangeWorkflow

Id record-product-audit-change. Creates changes that start confirmed, with actor_id as both created_by and confirmed_by, and stores every action with applied: true. It doesn’t touch the product and emits no event.

requestProductChangeWorkflow

Id mercur-request-product-change. Checks that the product is proposed, records a CHANGE_REQUESTED audit change with the message as external_note, and emits product.change-requested. Hooks: productChangeRequested with { product_id, message, additional_data }.

Steps

The module’s steps are exported from @mercurjs/core/workflows for your own workflows:
  • Create: createProductChangesStep, createProductChangeActionsStep, addProductChangeActionStep
  • Resolve: confirmProductChangesStep, declineProductChangeStep, cancelProductChangeStep
  • Update: updateProductChangeActionsStep, applyVariantImageLinksStep
  • Validate: validateNoPendingProductChangeStep, validateProductChangeIsPendingStep, confirmProductChangeValidationStep
The create, resolve, and updateProductChangeActionsStep steps compensate by deleting or restoring what they wrote. applyVariantImageLinksStep has no compensation, and the validation steps write nothing.