以magento1.9.3作为例子
添加以下代码到magento根目录,运行.
<?php
define('MAGENTO', realpath(dirname(__FILE__)));
ini_set('memory_limit', '32M');
set_time_limit (0);
require_once MAGENTO . '/app/Mage.php';
Mage::app();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->startSetup();
$entityTypeId = $setup->getEntityTypeId('customer');
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$setup->addAttribute('customer', 'mobile', array(
'input' => 'text',
'type' => 'text',
'label' => 'Mobile',
'visible' => 1,
'required' => 1,
'user_defined' => 1,
));
$setup->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'mobile',
'999' //sort_order
);
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'mobile');
$oAttribute->setData('used_in_forms', array('adminhtml_customer'));
$oAttribute->save();
$re = $setup->endSetup();
var_dump($re);