0

Magento 2.3.3

I am trying to create a product attribute which has the type "radio button". I am almost sure in Magento 1 it was possible to do just that. Now in Magento 2, I do not have the option "radio button" as type of option, only dropdown and some others. Am I missing something, or is it not possible?

Thanks!

1
  • Are you looking for Custom Options or Product Attribute? Commented Sep 4, 2020 at 10:16

1 Answer 1

0

Create Attribute following way :-

 $eavSetup->updateAttribute(
         \Magento\Catalog\Model\Product::ENTITY, 'custom_attribute_name', 
    [
        'type' => 'int',
        'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
        'frontend' => '',
        'label' => 'Custom Attribute Name',
        'input' => 'boolean',
        'group' => 'General',
        'class' => 'custom_attribute_name',
        'source' => 'Custom\Product\Model\YesNo',
        'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
        'visible' => true,
        'required' => true,
        'user_defined' => false,
        'default' => '1',
        'searchable' => false,
        'filterable' => false,
        'comparable' => false,
        'visible_on_front' => false,
        'used_in_product_listing' => true,
        'unique' => false
    ]
    );

After you add options like. Create File Custom\Product\Model\YesNo For Options

<?php
namespace Yourvendorname\Yourmodulename\Model;

class YesNo extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
{

    protected $_options;

    public function toOptionArray()
    {
         return array(
            array('value' => '1', 'label' => __('Yes')),
            array('value' => '0', 'label' => __('No'))
            ..................
         );
     }
     public function getAllOptions()
    {
        return $this->toOptionArray();
    }
}

You Can Add Options In toOptionArray() Function

THANKS.

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.