3

I have used this tutorial before for adding registration fields to the Magento registration page.

It has always worked, but since I have upgraded to Magento 1.4.2.0 it no longer does. The attributes I add no longer show up under the customers information tab in the backend like it did before and are not getting saved. The attributes install into the database fine though. I thought maybe the config.xml part had changed but I checked it against the core customer one and the attributes are sill shown the same way:

<flavour><create>1</create><update>1</update></flavour>

Something must have changed since the last 1.4.2 beta because it worked fine then. If someone has any ideas it would be greatly appreciated and I could finally get some sleep! Thanks in advance!

Roman Snitko
  • 3,655
  • 24
  • 29
Justin
  • 53
  • 2
  • 4

4 Answers4

4

I have been struggling with this one quite some time untill I figured it out. Since 1.4.2, the attributes to show in the admin's customer's form have to be in table customer_form_attribute.
You can add them with an upgrade in your module's setup, with this code:

$eavConfig = Mage::getSingleton('eav/config');
$attribute = $eavConfig->getAttribute('customer', 'your_attributes_code');
$attribute->setData('used_in_forms', array('adminhtml_customer'));
$attribute->save();

Hope that helps.

OSdave
  • 8,538
  • 7
  • 45
  • 60
  • great! thanks so much, the fields are showing up in the backend now. I still cannot get the fields to save the value in the frontend though. Have you been able to accomplish this? They will save if entered in the backend, but will not save when customer is created on registration page. – Justin Jan 03 '11 at 17:07
  • actually my attribute isn't filled in by the customer, it doesn't appear in the frontend forms, it's setup by an observer. The code I put is to see the input in the admin's forms: if you look into the customer_form_attribute table you'll see that there are other values possible, maybe you have to add the frontend form's value. – OSdave Jan 04 '11 at 09:40
  • Thanks David, I think you got me pointed in the right direction! I will post my final solution if and when I figure it out.. – Justin Jan 04 '11 at 19:49
2

Very usefull hints above, thank you David!

To make the new attributes saveable in frontend (register and edit) just expand the second parameter array of $attribute->setData like this:

$eavConfig = Mage::getSingleton('eav/config');
$attribute = $eavConfig->getAttribute('customer', 'flavour');
$attribute->setData('used_in_forms',   array('customer_account_edit',
                                             'customer_account_create',
                                             'adminhtml_customer'));
$attribute->save();

After that you will find 3 new entries in the customer_form_attribute table instead of one.

If you want to test this before and after this change, just insert

Mage::log('attrib: '. (string)$attribute->getAttributeCode());

after line 371 in app/code/core/Mage/Customer/Model/Form.php and you will see all the used attributes in the mage system log. (valid for mage 1.4.2.0)

0

FYI everyone, they removed the 'special code' in community edition that shows all the custom attributes. I use enterprise and we were considering community edition due to the savings. This is one of the hurdles we will have to overcome.

Doesn't answer the question, but explains probably why they removed it from the free edition. The code to display them is completely missing from the theme.

CarComp
  • 1,929
  • 1
  • 21
  • 47
0

try this one :

http://www.magento.cc/custom-accountregistration-fields.html

Bizboss
  • 7,792
  • 27
  • 109
  • 174
  • thanks for your reply. I have tried this one too and unfortunately it doesn't work either. I cannot figure out what has changed that makes this no longer work.. – Justin Dec 30 '10 at 14:19