Skip to content

Instantly share code, notes, and snippets.

@jreinke
Created January 25, 2012 20:12
Show Gist options
  • Save jreinke/1678387 to your computer and use it in GitHub Desktop.
Save jreinke/1678387 to your computer and use it in GitHub Desktop.
Example of how to add attribute to customer entity type in Magento
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute('customer', 'civility', array(
'label' => 'Civility',
'visible' => true,
'required' => false,
'type' => 'int',
'input' => 'select',
'user_defined' => '1',
'source' => 'eav/entity_attribute_source_table',
));
$tableOptions = $installer->getTable('eav_attribute_option');
$tableOptionValues = $installer->getTable('eav_attribute_option_value');
$attributeId = (int) $installer->getAttribute('customer', 'civility', 'attribute_id');
foreach (array('Mr', 'Mrs', 'Miss') as $sortOrder => $label) {
$data = array(
'attribute_id' => $attributeId,
'sort_order' => $sortOrder,
);
$installer->getConnection()->insert($tableOptions, $data);
$optionId = (int) $installer->getConnection()->lastInsertId($tableOptions, 'option_id');
$data = array(
'option_id' => $optionId,
'store_id' => 0,
'value' => $label,
);
$installer->getConnection()->insert($tableOptionValues, $data);
}
$installer->endSetup();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment