Customer, magento: magento1 add custom attributes to customer: data-licensecc & gt; in the module's SQL file: startSetup (); $ eavConfigMage :: getSingleton (eavconf data-id = "1190000005008696" data-license = "cc">
In the SQL file of the module:
/**
//echo 12345;$installer = $this;$installer->startSetup();$eavConfig = Mage::getSingleton('eav/config');$store = Mage::app()->getStore(Mage_Core_Model_App::ADMIN_STORE_ID);$sortOrder = 999;$attributes = array('chuanzhen' => array( 'type' => 'varchar', 'label' => 'chuanzhen', 'input' => 'text', 'required' => 1, 'global' => 1, 'is_visible' => 1, 'is_system' => 0, 'position' => 40, 'is_user_defined' => 1, 'sort_order' => $sortOrder++,),'sex' => array( 'type' => 'int', 'label' => 'Sex', 'input' => 'radio', 'required' => 1, 'is_visible' => 1, 'is_system' => 0, 'global' => 1, 'is_user_defined' => 1, 'position' => 44, 'sort_order' => $sortOrder++,),
);
/Save the preceding attributes to the database and add them to the page form./
Foreach ($ attributes as $ attributeCode => $ data) {$ installer-> addAttribute ('customer', $ attributeCode, $ data );} foreach ($ attributes as $ attributeCode => $ data) {$ attribute = $ eavConfig-> getAttribute ('customer', $ attributeCode ); $ attribute-> setWebsite ($ store-> getWebsite (); $ attribute-> addData ($ data ); if (false = ($ data ['is _ system'] = 1 & $ data ['is _ visable'] = 0 )) {$ usedInForms = array ('customer _ account_create ', 'Customer _ account_edit', 'checkout _ register ', 'adminhtml _ custom', 'adminhtml _ checkout '); $ attribute-> setData ('used _ in_forms ', $ usedInForms);} $ attribute-> save ();} $ installer-> endSeup (); add the properties of the drop-down box, add gender male and famale: $ installer-> startSetup (); $ installer-> addAttribute ('customer', 'gender', array ('label' => 'gender ', 'visible '=> true, 'required' => false, 'type' => 'int', 'input' => 'select ', 'Source' => 'eav/entity_attribute_source_table ',));
$tableOptions = $installer->getTable('eav_attribute_option'); $tableOptionValues = $installer->getTable('eav_attribute_option_value'); // add options for level of politeness $attributeId = (int)$installer->getAttribute('customer', 'gender', 'attribute_id'); foreach (array('Male', 'Female') as $sortOrder => $label) { // add option $data = array( 'attribute_id' => $attributeId, 'sort_order' => $sortOrder, ); $installer->getConnection()->insert($tableOptions, $data); // add option label $optionId = (int)$installer->getConnection()->lastInsertId($tableOptions, 'option_id'); $data = array( 'option_id' => $optionId, 'store_id' => 0, 'value' => $label, ); $installer->getConnection()->insert($tableOptionValues, $data);
}
$installer->endSetup();
The above describes how magento1 adds custom attributes to the customer, including the customer and magento content, and hopes to help those who are interested in the PHP Tutorial.