Creating customer attributes in your Magento website

You can more attribute to the attributes array.

require_once 'app/Mage.php'; Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); $prefix = Mage::getConfig()->getTablePrefix(); $entityTypeID = 1; //you can add more attributes to the array and it will create $attributes = array( array("attributeCode" => 'customAttributeCode', "attributeTitle" => 'custom Attribute Name', "inputType" =>'text', "backendType" => 'varchar', "isRequired" => 1 ) ); $sortOrder =69; foreach($attributes as $key=>$attribute){ $attributeCode = $attribute["attributeCode"]; $backendType = $attribute["backendType"]; $inputType = $attribute["inputType"]; $attributeTitle = $attribute["attributeTitle"]; $isRequired = $attribute["isRequired"]; $sortOrder++; $query = " INSERT INTO `" . $prefix . "eav_attribute` SET `attribute_id` =NULL, `entity_type_id` = $entityTypeID, `attribute_code` = '$attributeCode', `attribute_model` =NULL, `backend_model`=NULL, `backend_type` ='$backendType', `backend_table` = NULL, `frontend_model` =NULL, `frontend_input` = '$inputType', `frontend_label` = ' " . mysql_escape_string($attributeTitle) ."', `frontend_class` = NULL, `source_model` = NULL, `is_required` = '$isRequired', `is_user_defined` = 0, `default_value` = NULL, `is_unique` = '0', `note`= 'created for wholesale' "; $write = Mage::getSingleton('core/resource')->getConnection('core_write'); $write->query($query); $attributeId = $write->lastInsertId(); if($attributeId){ $query = " INSERT INTO `" . $prefix . "customer_eav_attribute` SET `attribute_id` = '$attributeId' , `is_visible` ='1' , `input_filter` = NULL , `multiline_count` = 1 , `validate_rules` = NULL , `is_system` = '0' , `sort_order`= '$sortOrder', `data_model` = NULL "; $write->query($query); $query = " INSERT INTO `" . $prefix . "eav_entity_attribute` SET `entity_attribute_id` = NULL , `entity_type_id` = '1' , `attribute_set_id` ='1' , `attribute_group_id` = '1' , `attribute_id` = $attributeId , `sort_order`='$sortOrder' "; $write->query($query); $query = " INSERT INTO `" . $prefix . "customer_form_attribute` ( `form_code` , `attribute_id` ) VALUES ( 'adminhtml_customer', '$attributeId' ), ( 'customer_account_create', '$attributeId' ), ( 'customer_account_edit', '$attributeId' ) "; $write->query($query); } }