Skip to content

Instantly share code, notes, and snippets.

@Marko-M
Forked from jzahedieh/customer-install-0.1.0.php
Created February 6, 2017 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marko-M/09d63501386bffbacd5050c192cf51e7 to your computer and use it in GitHub Desktop.
Save Marko-M/09d63501386bffbacd5050c192cf51e7 to your computer and use it in GitHub Desktop.
Magento Customer Attribute Setup
<?php
/* @var $installer Mage_Customer_Model_Resource_Setup */
$installer = Mage::getResourceModel('customer/setup','customer_setup');
$installer->startSetup();
if (!$installer->getAttributeId('customer', 'attribute_name')) {
$installer->addAttribute('customer', 'attribute_name', array( // TABLE.COLUMN: DESCRIPTION:
/** Standard values defined @see Mage_Eav_Model_Entity_Setup::_prepareValues() */
'label' => 'Label', // eav_attribute.frontend_label admin input label
'backend' => 'module/class_name', // eav_attribute.backend_model backend class (module/class_name format)
'type' => 'varchar', // eav_attribute.backend_type backend storage type (varchar, text etc)
'table' => 'module/config_name', // eav_attribute.backend_table backend table (resource config format)
'frontend' => 'module/class_name', // eav_attribute.frontend_model admin class (module/class_name format)
'input' => 'input_name', // eav_attribute.frontend_input admin input type (select, text, textarea etc)
'frontend_class' => null, // eav_attribute.frontend_type class associated to the element.
'source' => null, // eav_attribute.source_model admin input source model (for selects) (module/class_name format)
'required' => true, // eav_attribute.is_required required in admin
'user_defined' => false, // eav_attribute.is_user_defined editable in admin attributes section, false for not
'default' => null, // eav_attribute.default_value admin input default value
'unique' => false, // eav_attribute.is_unique unique value required
'note' => null, // eav_attribute.note admin input note (shows below input)
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, // eav_attribute.is_global scope
/** Unique values defined @see Mage_Customer_Model_Resource_Setup::_prepareValues() */
'visible' => true, // customer_eav_attribute.is_visible visible on admin
'system' => false, // customer_eav_attribute.is_system is system defined, should be false
'input_filter' => null, // customer_eav_attribute.input_filter field filter like datatime / date
'multiline_count' => 0, // customer_eav_attribute.multiline_count multiline form field area line count
'validate_rules' => null, // customer_eav_attribute.validate_rules serialised validation rules.
'position' => 0, // customer_eav_attribute.sort_order position / sort order
));
}
/** For enterprise @see app/code/core/Enterprise/CustomerSegment/sql/enterprise_customersegment_setup/mysql4-upgrade-0.0.6-0.0.7.php */
$installer->updateAttribute('customer', 'created_at', 'is_used_for_customer_segment', 1);
/**
* Set the customer attribute to be used in various forms.
*/
$attribute = $installer->getAttribute('customer', 'attribute_name');
$usedInForms = array(
'customer_account_create',
'customer_account_edit',
'checkout_register',
'adminhtml_customer'
);
$attribute->setData('used_in_forms', $usedInForms);
$attribute->save();
$installer->endSetup();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment