[5.x]: Default variant set from a provisional draft does not stick; two variants end up flagged isDefault
@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.defaultVariantIdpoints 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.sortOrderfor 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
- Open a product with several variants, drag a variant to a new position (provisional draft gets created).
- Use "Set default variant" on another variant.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.