Magento 2 module that lets merchants choose a default pre-selected variant for configurable products. The chosen variant's options (e.g. Color = White) are selected automatically for customers on:
- Product pages (PDP)
- Category / search listing pages (swatch renderer)
Works on Luma and Hyvä (and any theme using core's configurable JSON config) — the module ships zero frontend files.
The module stores the chosen child product's entity_id in a hidden product attribute (sw_default_variant_id). On the storefront, a single plugin on
Magento\ConfigurableProduct\Block\Product\View\Type\Configurable::getJsonConfig()
resolves that child's super-attribute options and sets them as Magento's native preconfigured values. Core then emits them as defaultValues in the standard swatch/configurable JSON config, which both Luma's swatch-renderer.js/configurable.js and Hyvä's initConfigurableOptions() already honor natively.
Because the listing swatch block (Magento\Swatches\Block\Product\Renderer\Listing\Configurable) extends the same base block, one plugin covers PDP and listings alike. A second plugin adds the attribute to product collections so listing pages can see it.
- Open any configurable product in the admin.
- In the Configurations panel, find the Default Pre-Selected Option dropdown, listing the product's current variants by their configurable attribute labels and SKU.
- Pick a variant (or -- No default selection -- to disable) and Save.
mkdir -p app/code/ShopWhizzy/ConfigurablePreSelect
# copy the module files there, then:
bin/magento module:enable ShopWhizzy_ConfigurablePreSelect
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento cache:flushcomposer config repositories.shopwhizzy-configurablepreselect vcs https://github.com/ShopWhizzy/module-configurable-pre-select
composer require shopwhizzy/module-configurable-pre-select
bin/magento module:enable ShopWhizzy_ConfigurablePreSelect
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento cache:flush- Magento Open Source / Adobe Commerce 2.4.x
- PHP 8.1+
- Themes: Luma, Hyvä, and any theme consuming core's configurable/swatch JSON config
- The attribute is created by a data patch and assigned to all product attribute sets, so it works for every configurable product regardless of attribute set.
- The attribute is hidden from the standard attribute UI (
visible = false); the admin field is injected into the Configurations panel via a UI component form modifier with an explicitdata.product.*dataScope. - If the selected variant is later disabled or unassigned, the module silently falls back to no pre-selection — no errors on the storefront.
- Multi-attribute configurables are supported: all of the chosen child's super-attribute options are pre-selected.
Open Software License (OSL 3.0)