1

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?

3
  • howmany checkbox you want? Commented Sep 6, 2017 at 16:05
  • You should be using 'input' => 'boolean' not int Commented Sep 6, 2017 at 19:57
  • one checkbox @abhishek Commented Sep 7, 2017 at 13:04

1 Answer 1

0

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

$categorySetup->addAttribute(
'catalog_category',
'page_not_found',
array(
    '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 and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.