Magento : Adding Custom Attribute to your Customers!

June 1, 2011 § 13 Comments

There are couple resources you need to go through,

  1. Magento Wiki : Custom Account/Registration Fields (2010-JUNE-25)
  2. Fontis : Know More About Your Customers – Adding Custom Signup Attributes ( 2009-JUN-15)
  3. Stackover : Can no longer add registration fields in Magento (2010- DEC-28)

but the resource is so scattered, so I decided to gather the info here.

First of all, following people shall take the credit : Chris Woodard, AlexSz, phlux0r, bolasevich, Denis Margetic , Brian Wozeniak

So let’s get started, first of all,  backup your database first. Secondly, view the Magento Wiki : Custom Account/Registration Fields – the original post to get the first impression. I would recommend the Fontis : Know More About Your Customers – Adding Custom Signup Attributes as it suggested a non-core modification method to tackle the issue, and a clearer article structure as well.

Please following Fontis : Know More About Your Customers – Adding Custom Signup Attributes until step 4 finished.

For Step 5 we would modify the code a bit to make it magento 1.5 compatible.

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('customer', 'flavour', array(
	'label'		=> 'Ice Cream Flavour',
	'type'		=> 'varchar',
	'input'		=> 'text',
	'visible'	=> true,
	'required'	=> true,
	'position'	=> 1,
/* From Stackover*/
$eavConfig = Mage::getSingleton('eav/config');
$attribute = $eavConfig->getAttribute('customer', 'flavour');
$attribute->setData('used_in_forms', array('adminhtml_customer','customer_account_create','customer_account_edit'));  //enable all action
//$attribute->setData('used_in_forms', array('adminhtml_customer'));  //to make the attribute can be created in backend only
//$attribute->setData('used_in_forms', array('customer_account_create')); //to make the attribute can be created in registration only
//$attribute->setData('used_in_forms', array('customer_account_edit')); // to make the attribute can be edited in the frontend only


Not sure if we can call setData for the attribute in a single go, but it illustrates the idea

After that follow the rest of the steps is fine.

Database Hack

If you already went through the articles before coming to this one. You can always use the database style to sort things out.

From Brian Wozeniak :

Magento 1.5 got a new table called  customer_form_attribute that other articles didnt cover.

INSERT INTO `database`.`customer_form_attribute` (`form_code`, `attribute_id`) VALUES ('adminhtml_customer', 'YOUR_ATTRIBUTE_ID');
INSERT INTO `database`.`customer_form_attribute` (`form_code`, `attribute_id`) VALUES ('customer_account_create', 'YOUR_ATTRIBUTE_ID');
INSERT INTO `database`.`customer_form_attribute` (`form_code`, `attribute_id`) VALUES ('customer_account_edit', 'YOUR_ATTRIBUTE_ID');

It should save some times 😛


Where Am I?

You are currently browsing entries tagged with 1.5 at Nick Wan L.K..