I added new customer fields (attributes) by installer in my Magento extension. I want group this fields and show in separate tabs on customer edit page.

I can make it in installer with this code

    ->getAttribute('customer', $attr_code)
    ->setData('used_in_forms', [$form_code])

But for this I need add new value to enum list for field form_code in table customer_form_attribute

I know how make this with SQL in mysql console:

  1. Check enum list by SHOW CREATE TABLE customer_form_attribute
  2. Change column by ALTER TABLE customer_form_attribute ...

But I need make this modification in my extension installer.

How I can make it?

  • Can you add your full install script?
    – sv3n
    Mar 20 '18 at 23:26

I found solution. It working on my local server. Don't try on production yet.

There is code for modify column form_code in table customer_form_attribute

$form           = 'my_new_form_code';

$table_array = $installer->getConnection()->describeTable('customer_form_attribute');
if (isset($table_array['form_code'])) {
    if (stripos($table_array['form_code']['DATA_TYPE'], $form) === false) {
        $table_array['form_code']['DATA_TYPE'] = substr($table_array['form_code']['DATA_TYPE'], 0, -1) . ", '" . $form . "')";
        $installer->getConnection()->modifyColumn('customer_form_attribute', 'form_code', $table_array['form_code']['DATA_TYPE'] . " NOT NULL");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.