createAndLinkProductAttributesToProductWorkflow, the engine
behind the product attribute batch endpoint. One call can attach new attributes,
detach existing ones, and update selections, applied in the order
remove → add → update so a same-call remove and re-add of one attribute
resolves correctly.
Run the batch workflow
src/api/custom/products/[id]/attributes/route.ts
The three operations
Each entry inadd is one of the ProductAttributeBatchAdd forms:
remove takes attribute ids to detach; update carries
ProductAttributeBatchUpdate entries adjusting an existing selection.
For a variant-axis attribute,
value_ids is the per-product subset of the
mirror option’s values. The product’s variants are generated from exactly that
subset. See Variant axes.