Magento add custom input field to customer account form in admin


/ Published in: PHP
Save to your folder(s)

The fastest way is to create a php file and access it through browser add the following content to file.


Copy this code and paste it in your HTML
  1. require_once MAGENTO . '/../app/Mage.php';
  2. Mage::app();
  3.  
  4. $newFields = array(
  5. 'custom_attribute' => array(
  6. 'type' => 'text',
  7. 'label' => 'Customer Custom Attribute'
  8. )
  9. );
  10.  
  11. $entities = array('customer');
  12.  
  13. $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
  14. foreach($newFields as $attributeName => $attributeDefs) {
  15. foreach ($entities as $entity) {
  16. $setup->addAttribute($entity, $attributeName, array(
  17. 'position' => 1,
  18. 'type' => $attributeDefs['type'],
  19. 'label' => $attributeDefs['label'],
  20. 'global' => 1,
  21. 'visible' => 1,
  22. 'required' => 0,
  23. 'user_defined' => 1,
  24. 'searchable' => 0,
  25. 'filterable' => 0,
  26. 'comparable' => 0,
  27. 'visible_on_front' => 1,
  28. 'visible_in_advanced_search' => 0,
  29. 'unique' => 0,
  30. 'is_configurable' => 0,
  31. 'position' => 1,
  32. ));
  33. }
  34. }
  35.  
  36. OR
  37.  
  38. <?php
  39.  
  40. $installer = $this;
  41.  
  42. $installer->startSetup();
  43.  
  44. $installer->addAttribute('customer', 'interested',array(
  45. 'type' => 'varchar',
  46. 'input' => 'text',
  47. 'visible' => true,
  48. 'label' => 'Interested sales',
  49. 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
  50. 'required' => false
  51. ));
  52.  
  53. $installer->endSetup();

URL: http://stackoverflow.com/questions/5185727/magento-add-custom-input-field-to-customer-account-form-in-admin

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.