Question

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

Mage::getSingleton('eav/config')
    ->getAttribute('customer', $attr_code)
    ->setData('used_in_forms', [$form_code])
    ->save();

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?

Was it helpful?

Solution

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");
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top