How to add radio button to set default value for product custom options (Customizable Options) in Magento2 Admin grid
Magento – How to add radio button to set default value for Customizable Options in Magento2
custom-optionsdefault valuesmagento-2.1product
Best Answer
Here is the cleanest way I found to set a default value for customizable options :
(Based on answers on this similar question)
Note : I will assume you work on an already created module which I'll call
Vendor_Module
.1. Add
is_default
column tocatalog_product_option_type_value
tableNote : Don't forget to change the version compared according to your module
2. Define and create a plugin to add the checkbox element in the back office
Note : Here we use
Magento\Ui\Component\Form\Element\Checkbox
instead ofMagento\Ui\Component\Form\Element\Radio
component as it seems Magento never defines it in its Form Elements.See
vendor\magento\module-ui\view\base\ui_component\etc\definition.xml
line 112+3. Overwrite
Magento\Catalog\Block\Product\View\Options\Type\Select
to check the element which has been chosen as "Default element".4. Upgrade your module version and update the database
Upgrade your
setup_version
inapp/code/Vendor/Module/etc/module.xml
Update your
version
inapp/code/Vendor/Module/composer.json
Run following commands :