Skip to main content
The Product Attribute domain exports 11 workflows from @mercurjs/core/workflows: 7 that manage the catalog and 4 that attach attributes to products. Run each one with workflow(container).run({ input }). When a step fails, the steps that already ran undo their work through their compensation functions.

Catalog workflows

These workflows create, change, and delete attributes and values. They keep the mirror ProductOption of a variant axis in step.

createProductAttributesWorkflow

Creates attributes and their values. For each multi_select attribute with is_variant_axis, it first creates a global ProductOption (is_exclusive: false) titled with the attribute name, then links the values to its option values. Id create-product-attributes.
  • Returns: ProductAttributeDTO[]
  • Hooks: validate with { input }, productAttributesCreated with { attributes, additional_data }
  • Events: product-attribute.created per attribute

updateProductAttributesWorkflow

Updates every attribute matching selector. When update.name is set, it also renames the mirror option of each axis attribute. Id update-product-attributes.
  • Returns: ProductAttributeDTO[]
  • Hooks: validate with { input }, productAttributesUpdated with { attributes, additional_data }
  • Events: product-attribute.updated per attribute

deleteProductAttributesWorkflow

Soft-deletes attributes and their values, then deletes the mirror options of axis attributes. It throws NOT_ALLOWED if any value of an attribute is linked to a product. Id delete-product-attributes.
  • Returns: nothing
  • Hooks: validate with { input }, productAttributesDeleted with { ids, additional_data }
  • Events: product-attribute.deleted per id

createProductAttributeValuesWorkflow

Adds values to one attribute. For an axis, it first adds the names to the mirror option and stores each new option value’s id. Id create-product-attribute-values.
  • Returns: ProductAttributeValueDTO[]
  • Hooks: validate with { input }, productAttributeValuesCreated with { values, additional_data }
  • Events: product-attribute-value.created per value

updateProductAttributeValuesWorkflow

Updates every value matching selector. When the values belong to exactly one axis attribute, it rewrites that option’s values from the attribute’s value names. Id update-product-attribute-values.
  • Returns: ProductAttributeValueDTO[]
  • Hooks: validate with { input }, productAttributeValuesUpdated with { values, additional_data }
  • Events: product-attribute-value.updated per value

deleteProductAttributeValuesWorkflow

Soft-deletes values. When they belong to exactly one axis attribute, it rewrites that option’s values from the remaining value names. Id delete-product-attribute-values.
  • Returns: nothing
  • Hooks: validate with { input }, productAttributeValuesDeleted with { ids, additional_data }
  • Events: product-attribute-value.deleted per id

upsertProductAttributeValuesWorkflow

Creates values without an id and updates values with one, for a single attribute. For an axis, it adds any new names to the mirror option first. Id upsert-product-attribute-values.
  • Returns: ProductAttributeValueDTO[], created values first
  • Hooks: none
  • Events: none

Product attachment workflows

These workflows attach attributes to products, write the product_attribute_value_link pivot, and attach or detach axis options on the product. Their input types are ProductAttributeBatchAdd and ProductAttributeBatchUpdate from @mercurjs/types.

createAndLinkProductAttributesToProductWorkflow

The batch engine. It runs the remove, add, and update workflows below in that order, skipping any list that’s empty. Id create-and-link-product-attributes-to-product.
  • Returns: nothing
  • Hooks: validate with { input }, productAttributesLinked with { product_id, additional_data }
  • Events: none of its own. Nested catalog workflows emit theirs

addProductAttributesToProductWorkflow

Attaches attributes. It creates inline attributes and their exclusive options, creates text and unit values, attaches axis options with the selected subset, and links every value to the product. Id add-product-attributes-to-product. The input can also be an array of { product_id, add } objects to attach to several products in one run. It has no hooks and emits no events.

removeProductAttributesFromProductWorkflow

Detaches attributes. It throws NOT_ALLOWED for a required attribute unless the id is also in readd. It then detaches global axis options, drops the value links, and deletes inline attributes through deleteProductAttributesWorkflow. Id remove-product-attributes-from-product.

updateProductAttributesOnProductWorkflow

Changes selections. It resolves value_ids into an add and remove delta, moves global axis option values, swaps text, unit, and toggle values, adds or deletes values of an inline axis, and renames inline attributes from title. Id update-product-attributes-on-product.
Changes made by these workflows land on the product right away. To route a store’s attribute edits through review, run productEditUpdateAttributesWorkflow from the Product edits domain, which applies the batch engine once the change is confirmed.

Steps

The domain also exports its steps for use in your own workflows: