shopwhizzy / module-configurable-pre-select
Lets merchants pick a default variant on configurable products, pre-selected automatically on product and category pages. Theme-agnostic (Luma & Hyvä) with zero frontend files.
Package info
github.com/shopwhizzy/magento2-configurablepreselect
Type:magento2-module
pkg:composer/shopwhizzy/module-configurable-pre-select
Requires
- php: >=8.1
- magento/framework: >=103.0
- magento/module-catalog: >=104.0
- magento/module-configurable-product: >=100.4
- magento/module-eav: >=102.1
- magento/module-ui: >=101.2
README
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.
How it works
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.
Admin usage
- 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.
Installation
app/code
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:flush
Composer (from a VCS repository)
composer 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
Compatibility
- Magento Open Source / Adobe Commerce 2.4.x
- PHP 8.1+
- Themes: Luma, Hyvä, and any theme consuming core's configurable/swatch JSON config
Technical notes
- 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.
License
Open Software License (OSL 3.0)