0

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?

1 Answer 1

0

Since you just have options Yes/No. Replacing 'input' => 'select' with 'input' => 'boolean' will solve your problem.

Hope it was helpful.

Thanks

1
  • Solved using a different source. Commented Sep 4, 2020 at 14:12

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.