I have created a custom attribute in magento 2 for product using a source Magento\Eav\Model\Entity\Attribute\Source\Boolean
Here is the code
if(!$eavSetup->getAttributeId(\Magento\Catalog\Model\Product::ENTITY, 'purchase_unit')) {
$eavSetup->addAttribute(
Product::ENTITY,
'purchase_unit',
[
'group' => 'Rocket',
'type' => 'int',/* Data type in which formate your value save in database*/
'backend' => '',
'frontend' => '',
'label' => 'Purchase Unit', /* lablel of your attribute*/
'input' => 'select',
'class' => '',
'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
/*Scope of your attribute */
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => '0',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => false,
'unique' => false
]
);
}
The attribute is getting created and also displays in product page. The issue is it displays YES as default value which is 1. How to solve this problem?