magento adding custom customer field by mysql insert queries
Add a custom boolean customer field in Magento by directly inserting values into Magento mysql database.
[code language=”sql”]
INSERT INTO `eav_attribute`
(`attribute_id`, `entity_type_id`, `attribute_code`, `backend_model`, `backend_type`, `frontend_input`, `frontend_label`, `source_model`, `is_required`, `is_user_defined`, `default_value`)
VALUES
(‘999’, ‘1’, ‘yes_no_flag’, NULL, ‘int’, ‘boolean’, ‘Yes No Flag’, ‘eav/entity_attribute_source_boolean’, ‘0’, ‘1’, ‘0’);
INSERT INTO `customer_form_attribute` (`form_code`,`attribute_id`)
VALUES (‘customer_account_edit’, ‘999’), (‘adminhtml_customer’, ‘999’);
INSERT INTO `customer_eav_attribute` (`attribute_id`, `is_visible`, `input_filter`, `validate_rules`, `is_system`, `sort_order`, `is_used_for_customer_segment`)
VALUES (‘999’, ‘0’, NULL, ‘a:0:{}’, ‘0’, ‘999’, ‘0’);
INSERT INTO `eav_entity_attribute` (`entity_type_id`, `attribute_set_id`, `attribute_group_id`, `attribute_id`, `sort_order`)
VALUES (‘1’, ‘1’, ‘1’, ‘999’, ‘1000’);
[/code]
Load customer, and set the custom customer field.
[code language=”php”]
$customer = Mage::getModel(‘customer/customer’)->load(12345);//load by id
$customer->setData(‘yes_no_flag’, 1);
$customer->save();
[/code]
Search within Codexpedia

Search the entire web
