1

I added my customer attribute.

enter image description here

But I want to display these fields as checkboxes. I created checkbox in the frontend easily but the backend is not. And then save to the database. Please help me. Thanks.

my script

<?php
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('customer', 'biz_confirmation', array(
    'label'     => 'Business Customer Confirmation',
    'type'      => 'int',
    'input'     => 'checkbox',
    'visible'   => true,
    'required'  => true,
    'default'   => '0',
));
$setup->addAttribute('customer', 'marketing_consent', array(
    'label'     => 'Marketing Consent',
    'type'      => 'int',
    'input'     => 'checkbox',
    'visible'   => true,
    'required'  => false,
    'default'   => '0',
));
$setup->addAttribute('customer', 'b2b_contact_consent', array(
    'label'     => 'B2B Contact Consent',
    'type'      => 'int',
    'input'     => 'checkbox',
    'visible'   => true,
    'required'  => false,
    'default'   => '0',
));
$setup->addAttribute('customer', 'biz_confirmation_time', array(
    'label'     => 'Business Customer Confirmation Update Time',
    'type'      => 'datetime',
    'input'     => 'datetime',
    'visible'   => false,
    'required'  => false,
));
$setup->addAttribute('customer', 'mkt_consent_updated_time', array(
    'label'     => 'Marketing Consent Update Time',
    'type'      => 'datetime',
    'input'     => 'datetime',
    'visible'   => false,
    'required'  => false,
));
$setup->addAttribute('customer', 'b2b_consent_updated_time', array(
    'label'     => 'B2B Contact Consent Update Time',
    'type'      => 'datetime',
    'input'     => 'datetime',
    'visible'   => false,
    'required'  => false,
));
$attributeCodes = array(
    'biz_confirmation',
    'marketing_consent',
    'b2b_contact_consent',
    'biz_confirmation_time',
    'mkt_consent_updated_time',
    'b2b_consent_updated_time'
);

foreach($attributeCodes as $code) {
    $attribute = Mage::getSingleton("eav/config")->getAttribute('customer', $code);
    $used_in_forms = array(
        'adminhtml_customer',
        'checkout_register',
        'customer_account_create',
        'customer_account_edit');
    $attribute->setData("used_in_forms", $used_in_forms)
        ->setData("is_used_for_customer_segment", true)
        ->setData("is_system", 0)
        ->setData("is_user_defined", 1)
        ->setData("is_visible", 1)
        ->setData("sort_order", 100);
    $attribute->save();
}
2
  • please send your script code .
    – Shorabh
    Commented Aug 27, 2018 at 4:12
  • @Shorabh i updated
    – Thanh TN
    Commented Aug 27, 2018 at 4:30

1 Answer 1

0

Try boolean instead of checkbox.

 'input' => 'boolean',

Reference: https://community.magento.com/t5/Magento-2-x-Technical-Issues/Customer-custom-attribute-with-checkbox-input-throws-exception/m-p/78907/highlight/true#M3323

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.