Skip to main content
Create a variant axis such as Size, then create a product that uses part of it and has one variant per selected value. You need this whenever products in your catalog come in sizes, colors, or any other dimension shoppers pick between.

Before you begin

You need the following:
  • A Mercur server: an API app with @mercurjs/core registered through withMercur()
  • The concept: read Variant axes and product options to see how an axis maps to a Medusa ProductOption

Build the axis and the product

1

Create the axis attribute

An axis is a multi_select attribute with is_variant_axis: true. The workflow creates a global ProductOption titled Size with the same three values.
src/scripts/seed-size-axis.ts
Run it with npx medusa exec ./src/scripts/seed-size-axis.ts. Medusa keeps global option titles unique, so a second global axis named Size fails.
2

Create a product on the axis

Mercur’s createProductsWorkflow takes attributes and variants together. It attaches the axis with the values you pick, then creates the variants against it.
Run this inside an authenticated route handler, so req.auth_context.actor_id records who created the product. Each variant names its option value by the option title, which is the attribute name. The product only holds S and M, so those are the variants it can have.

Change the values a product uses

Run createAndLinkProductAttributesToProductWorkflow with an update entry to grow or shrink the subset. The workflow moves the option values on the product and the pivot links together.
After the run, the product offers M and L. Create the L variant with Medusa’s createProductVariantsWorkflow and options: { Size: "L" }.

Create an axis for one product

When only one product needs a dimension, add an inline axis instead of a global one. It creates an exclusive option (is_exclusive: true), a product-scoped multi_select attribute, and its values, and attaches them to the product.
An inline axis holds all of its values, so there’s no subset to pick. You add values to it later with update and add: [{ value: "Relaxed" }].

Add values to a global axis

createProductAttributeValuesWorkflow adds values to the attribute and to its global option in one run. Products don’t gain the new value until you add it to their subset.

Next steps