@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 mirrorProductOption of a variant axis in step.
createProductAttributesWorkflow
Creates attributes and their values. For eachmulti_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:
validatewith{ input },productAttributesCreatedwith{ attributes, additional_data } - Events:
product-attribute.createdper attribute
updateProductAttributesWorkflow
Updates every attribute matchingselector. When update.name is set, it also renames the mirror option of each axis attribute. Id update-product-attributes.
- Returns:
ProductAttributeDTO[] - Hooks:
validatewith{ input },productAttributesUpdatedwith{ attributes, additional_data } - Events:
product-attribute.updatedper attribute
deleteProductAttributesWorkflow
Soft-deletes attributes and their values, then deletes the mirror options of axis attributes. It throwsNOT_ALLOWED if any value of an attribute is linked to a product. Id delete-product-attributes.
- Returns: nothing
- Hooks:
validatewith{ input },productAttributesDeletedwith{ ids, additional_data } - Events:
product-attribute.deletedper 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. Idcreate-product-attribute-values.
- Returns:
ProductAttributeValueDTO[] - Hooks:
validatewith{ input },productAttributeValuesCreatedwith{ values, additional_data } - Events:
product-attribute-value.createdper value
updateProductAttributeValuesWorkflow
Updates every value matchingselector. 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:
validatewith{ input },productAttributeValuesUpdatedwith{ values, additional_data } - Events:
product-attribute-value.updatedper value
deleteProductAttributeValuesWorkflow
Soft-deletes values. When they belong to exactly one axis attribute, it rewrites that option’s values from the remaining value names. Iddelete-product-attribute-values.
- Returns: nothing
- Hooks:
validatewith{ input },productAttributeValuesDeletedwith{ ids, additional_data } - Events:
product-attribute-value.deletedper id
upsertProductAttributeValuesWorkflow
Creates values without anid 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 theproduct_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. Idcreate-and-link-product-attributes-to-product.
- Returns: nothing
- Hooks:
validatewith{ input },productAttributesLinkedwith{ 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, createstext 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 throwsNOT_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 resolvesvalue_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.