craftcms / craftcms/commerce

[5.x]: Default variant set from a provisional draft does not stick; two variants end up flagged isDefault

Open
#4,361 3 comments 0 reactions 1 assignee View on GitHub

@lukeholder is already working on this.

Since Sep 7, 2026.

Dominant language
PHP
Stars
240
Forks
173
Avg merge
5d 11h
Merged PRs (30d)
8

Description

What happened

Editors set the default variant via the "Set default variant" card action while the product is in a provisional draft (they had reordered variants first). After Save, the product still shows the previous default. In the database:

  • commerce_products.defaultVariantId points at the old variant, while the user's provisional draft row points at the new one.
  • Both the old and the new variant have commerce_variants.isDefault = true. We currently have 57 products in this state.
  • After applying such a draft, elements_owners.sortOrder for the canonical product no longer starts at 1 (e.g. 27..52), and on one product the order came out scrambled with gaps.

Setting the default without an open draft, or saving the reorder and the default change as two separate saves, works.

Looks related to #3564 / #3565.

Steps to reproduce
  1. Open a product with several variants, drag a variant to a new position (provisional draft gets created).
  2. Use "Set default variant" on another variant.
  3. Save.

Not reliably reproducible on a clean product for us; it happens for editors working on products that other users also have provisional drafts on.

Expected behavior

The chosen default and the new order are saved, and only one variant is flagged isDefault.

Craft CMS version

5.11.1

Craft Commerce version

5.7.3

PHP version

8.4

Operating system and version

Linux (Ploi)

Database type and version

PostgreSQL 17

Plugins & versions

Custom module (nested element listeners on products/variants)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.