Before you begin
You need the following:- A Mercur server: an API app with
@mercurjs/coreregistered throughwithMercur() - Workflow imports: every workflow on this page comes from
@mercurjs/core/workflows
Create the attribute
1
Run createProductAttributesWorkflow from a route
The workflow takes a list of attributes, each with its values, and returns the created records.Leaving out
src/api/admin/catalog-import/attributes/route.ts
product_id makes the attribute global. The service derives the handle material and a handle for each value.2
Scope it to categories
Pass A
category_ids to link the attribute to product categories in the same run. An attribute with no categories is offered for every product.unit attribute has no predefined values. Each product gets its own value when you attach the attribute.3
Add values later
Run For a variant axis, the workflow also adds the values to the mirror
createProductAttributeValuesWorkflow to add values to an existing select attribute. It takes one attribute_id and the new values.ProductOption.Attach custom data with additional_data
Every catalog workflow acceptsadditional_data and passes it to its completion hook. Register a handler on productAttributesCreated to store your own data next to the attribute without forking the workflow.
src/workflows/hooks/product-attributes-created.ts
additional_data: { imported_from: "legacy_pim" }. The workflow also exposes a validate hook that runs before anything is written, so you can throw there to reject the input.
Update or delete an attribute
updateProductAttributesWorkflow takes a selector and an update. Keep these rules in mind:
- Type is fixed: the service throws if
update.typediffers from the current type - Renames reach the option: changing
nameon an axis also renames itsProductOption - Deletes check usage:
deleteProductAttributesWorkflowthrowsNOT_ALLOWEDwhile any value is linked to a product
material, because handles are derived only on create.