Can anyone Help me to add radio button to custom options for product at product level for input type drop_down magento2 admin
Help me great
You can add custom option as radio button from magento 2 backend .
Follow the below steps :
For more reference refer below screenshot :
Backend
Frontend
If You want add to product level custom option look in these file path to add
your code
File Path : vendor/magento/module-catalog/Ui/DataProvider/Product/Form/Modifier/CustomOptions.php
step-1:Defing the variable
const FIELD_IS_DEFAULT_NAME = 'default_radio';
Step-2: in Function getCommonContainerConfig() You have to declare method to
use const variable
children' => [
static::FIELD_IS_DEFAULT_NAME => $this->getIsDefaultFieldConfig(150)
]
Step - 3:To which Grid type You want to Assign the Custom option
protected function getSelectTypeGridConfig($sortOrder)
{
return [
'children' => [
static::FIELD_IS_DEFAULT_NAME => $this-> getIsDefaultFieldConfig(200)
]
];
Step 4:To which Datatype You want to Assign the Custom option Should Define
Here
protected function getTypeFieldConfig($sortOrder)
{
'indexes' => [
static::FIELD_IS_DEFAULT_NAME
]
Step 5: code to call getIsDefaultFieldConfig(150) Which defined in step-2
protected function getIsDefaultFieldConfig($sortOrder)
{
return [
'arguments' => [
'data' => [
'config' => [
'label' => __('Default'),
'componentType' => Field::NAME,
'formElement' => Radio::NAME,
'dataScope' => static::FIELD_IS_DEFAULT_NAME,
'dataType' => Text::NAME,
'sortOrder' => $sortOrder,
'value' => '0',
'valueMap' => [
'true' => '1',
'false' => '0'
],
],
],
],
];
}
Before These All You need to define in xml for radio go for below Path
File Path:
vendor/magento/module-ui/view/base/ui_component/etc/definition.xml
Add below Code after checkbox
<!--these is added for defining the radio button -->
<radio class="Magento\Ui\Component\Form\Element\Radio">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/element/radio</item>
<item name="template" xsi:type="string">ui/form/field</item>
</item>
</argument>
</radio>
Step 6:You have create a column under your Database
catalog_product_option_type_value create a column that is defined in step 1.
You can See the radio box