Customer Attributes Wont Save

Posted on January 7, 2016
Written by

I recently came a cross an issue where a one or more customer attributes wont save. This turned out to be a for a number of reasons.

The only condition that Magento tells you about is that a customer attribute must be less than 21 characters. A client had made several new customer attributes one of which was alt_customer_f_name_1

I quickly realised that the first issue is that attribute codes can not contain numbers. Magento doesn’t like numbers for a many reasons but in this case it’s to do with Magento’s magic getters and setters.

Secondly I found out that if you have _f_ it wouldn’t save. If it was changed to _fr_ it did. Strange right ? But actually it makes sense. Magento’s magic methods strip out the underscores and camel case. For example – in this case it would become altCustomerFName() due to the two uppercase characters next to each other Magento can translate this back to underscores.

Annoyingly Magento doesn’t validate any of this when you save your new attributes.

For more details you can see the __call and_underscores methods inside the class Varien_Object located in lib/Varien/Object.php