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 ', ' is_user_defined ' and ' 1 ', ' Sort_orde R ' = + $sortOrder + +,), ' sex ' = = Array (' type ' = ' = ' int ', ' label ' = = ') Sex ', ' input ' = ' radio ', ' required ' = 1, ' is_visible ' and ' 1, ' Is_system ' and 0 , ' global ' = 1, ' is_user_defined ' and ' 1, ' position ', ' sort_order ' and $sortOr der++,),
);
/ to save the above attribute to the database and add it to the page form /
foreach ($attributes as $attributeCode = + $data) {$installer->addattribute (' Customer ', $attributeCode, $data);} foreach ($attributes as $attributeCode = = $data) {$attribute = $eavConfig->getattribute (' Customer ', $attributeCo DE); $attribute->setwebsite ($store->getwebsite ()); $attribute->adddata ($data); if (false = = = ($data [' is_system '] = = 1 && $data [' is_visible '] = = 0)) {$usedInForms = Array (' CU Stomer_account_create ', ' customer_account_edit ', ' checkout_register ', ' Adminhtml_customer ', ' adminhtml_checkout '); $attribute->setdata (' used_in_forms ', $usedInForms); } $attribute->save ();} $installer->endseup (); Add the properties of the drop-down box, add the gender male and Famale: $installer->startsetup (); $installer->addattribute (' Customer ', ' Gender ', Array (' label ' = ' gender ', ' visible ' = = Tru E, ' 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 the magento1 to the customer to add custom attributes, including the customer,magento aspects of the content, I hope that the PHP tutorial interested in a friend to help.