Skip to content

Instantly share code, notes, and snippets.

@rintoug
Created May 2, 2019 08: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 rintoug/50aa8ca358a6c728ffa59292b23605ec to your computer and use it in GitHub Desktop.
Save rintoug/50aa8ca358a6c728ffa59292b23605ec to your computer and use it in GitHub Desktop.
Create customer attribute in Magento 1
<?php
(PHP_SAPI !== 'cli' || isset($_SERVER['HTTP_USER_AGENT'])) && die('cli only');
$baseDir = dirname(dirname(__FILE__));
print $baseDir;
require_once($baseDir.'/app/Mage.php');
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$installer = new Mage_Customer_Model_Resource_Setup('core_setup');
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId = $setup->getEntityTypeId('customer');
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$installer->addAttribute('customer', 'mob_app_token', array(
'label' => 'Mobile App Token',
'visible' => true,
'input' => 'text',
'type' => 'varchar',
'source' => 'eav/entity_attribute_source_table',
'forms' => array('adminhtml_customer'),
'required' => 0,
'user_defined' => 0,
));
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "mob_app_token");
$setup->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'mob_app_token',
'99991' //sort_order
);
$used_in_forms=array();
$used_in_forms[]="adminhtml_customer";
$attribute->setData("used_in_forms", $used_in_forms)
->setData("is_used_for_customer_segment", true)
->setData("is_system", 0)
->setData("is_user_defined", 1)
->setData("is_visible", 1)
->setData("sort_order", 100)
;
$attribute->save();
$installer->endSetup();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment