0

After reading this thread that is sort of what we need to achieve (and does it with a custom attribute), it's not quite what I need and so I thought it would be good to ask the experts here.

We have a table, let's call it "customer_segment" with the following basic structure:

customer_segment_id
name

Then we've added a foreign key to the customer_entity table customer_segment_id that references the customer_segment_id in the customer_segment table.

Instead of hacking/overriding classes to get this field into the customer form, it seems logical that we can create a "static" attribute almost exactly like the customer group_id as it would also need to be attributed to orders, again just like group_id.

There are some hints in this post and the author appears to do a similar thing with the order entity.

1 Answer 1

0

If you have added the column like this:

$installer = $this;
$installer->startSetup();
$table = $installer->getTable('customer/entity');
$installer->getConnection()
    ->addColumn($table, 'segment_id', [
        'type'      => Varien_Db_Ddl_Table::TYPE_INTEGER,
        'unsigned'  => true,
        'nullable'  => true,
        'comment'   => 'Segment ID'
    ]);
$installer->getConnection()->addConstraint('FK_CUST_ENTITY_SEGMENT_ID',
    $table, 'segment_id',
    'customer_segment', 'customer_segment_id',
    'set null'
);
$installer->endSetup();

Then you can add the static attribute like this:

Mage::getModel('customer/attribute')->setData([
    'entity_type_id' => 1,
    'attribute_code' => 'segment_id',
    'backend_type' => 'static',
    'frontend_input' => 'text',
    'frontend_Label' => 'Segment ID',
    'is_user_defined' => 1,
    'is_visible' => 1,
    'used_in_forms' => ['adminhtml_customer', 'customer_account_edit', 'customer_account_create', 'checkout_register'] // Remove what you do not need
])
->save();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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