6

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

2 Answers 2

2

You can add custom option as radio button from magento 2 backend .

Follow the below steps :

  1. Logged in to magento 2 admin panel -> click on products ->catalog
  2. It will display all the products -> add/edit any products
  3. So on the product form you will see customizable options
  4. Click on customizable options -> Select option type as Radio button
  5. Add your options and its value and click on Save
  6. Check on frontend side it will display custom options with radio button .

For more reference refer below screenshot :

Backend

enter image description here

Frontend

enter image description here

1
  • Sorry It is not proper answers for above given question Manthan Dave,it is in drop_down option for showing default creating radio button at product level Mar 24, 2017 at 5:23
0

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

2
  • 1
    This solution is offering changing core code which is highly not recommended.
    – Timik
    Jun 13, 2017 at 22:12
  • Its not working ???
    – Mahi M
    Jan 4, 2019 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.