I created an InstallData class to add category attribute with checkbox input type. $eavSetup->addAttribute(\Magento\Catalog\Model\Category::ENTITY, 'attribute_id', [ 'type' => 'int', 'label' => 'Your Category Attribute Name', 'input' => 'checkbox', 'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean', 'visible' => true, 'default' => '0', 'required' => false, 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE, 'group' => 'Display Settings', ]);

The attribute displays a checkbox properly on the admin category edit page, but saving the category does not save checked value. If I change the input type to 'boolean', catch error - "Class boolean doesn't exist". How can I fix it to save checkbox value?

  • howmany checkbox you want? – Abhishek Panchal Sep 6 '17 at 16:05
  • You should be using 'input' => 'boolean' not int – Dava Gordon Sep 6 '17 at 19:57
  • one checkbox @abhishek – Begaiym Sep 7 '17 at 13:04

You can try below code to display boolean attribute (Yes/No) inside category page.

    'type' => 'int',
    'label' => 'Display on 404 Page',
    'input' => 'select',
    'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
    'sort_order' => 3,
    'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
    'group' => 'General Information',

Note: please change your values according to your requirement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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