Commerce as Code

Commerce as Code is the practice of managing an ecommerce store’s configuration, data models, and custom business logic in version control. Teams review changes in pull requests, test them in staging, and deploy them to production.

When your storefront starts showing material on apparel products, the catalog needs that field in staging and production. Put the field in Git so the same definition you test in staging ships to production.

How does configuration as code work in ecommerce?

Configuration as code puts store settings in version-controlled files. Teams use the same approach for product types, content models, and attributes. That’s schema as code.

To add Material, first export your staging configuration to config.yml with Saleor Configurator. Set SALEOR_URL to the staging GraphQL endpoint and SALEOR_TOKEN to a staging app token.

npx @saleor/configurator introspect --url "$SALEOR_URL" --token "$SALEOR_TOKEN"

Add Material to the Apparel product type in the exported file. This excerpt defines it as a text attribute shared across the product’s variants.

productTypes:
  - name: Apparel
    isShippingRequired: true
    productAttributes:
      - name: Material
        inputType: PLAIN_TEXT

Preview what will change in staging and review the YAML in a pull request.

npx @saleor/configurator diff --url "$SALEOR_URL" --token "$SALEOR_TOKEN"

Deploy the reviewed file to staging. Check that an editor can enter a material on an apparel product and that the storefront displays it.

npx @saleor/configurator deploy --url "$SALEOR_URL" --token "$SALEOR_TOKEN"

Before deploying to production, preview the diff against that environment and check any settings that should differ between environments. Then deploy the reviewed change to production.

The Configurator docs show how to export, preview, and deploy configuration. The same workflow applies to shipping: the multi-region recipe covers channels, warehouses, and shipping zones.

How does infrastructure as code fit into ecommerce?

Infrastructure as code defines what the store runs on, such as hosting and queues for background jobs. Configuration as code defines how the store operates. For a regional launch, a team might provision infrastructure for its storefront and apps, then use Configurator to set up the sales channel, warehouse, and shipping zone in Saleor.

How does Commerce as Code support ecommerce automation?

A deployment pipeline can run Configurator’s diff automatically before each release to show which ecommerce settings will change. If someone edits a shipping zone directly in production, the diff can also show where the live settings differ from Git. That difference is configuration drift.

How teams change commerce logic

Custom logic follows the same review and deployment process. A team can write a Saleor App that supplies a decision during checkout through a synchronous webhook, such as which delivery options to show. The team keeps the app code in Git and tests those options in staging before deploying the app.

Decomposable commerce gives teams a working platform they can change one capability at a time. Commerce as Code gives them a record of what changed and a repeatable way to put the change into production.

Read the original Commerce as Code article for the thinking behind the approach.

Bring your next commerce change into Git