Adding Custom Signup Attributes in Magento 1.7

前端 未结 3 823
梦毁少年i
梦毁少年i 2021-02-06 19:07

I have scoured the web for tutorials for adding custom signup attributes in Magento. While there are a few solid tutorials out there, my favorite being this one: custom customer

3条回答
  •  天命终不由人
    2021-02-06 19:21

    you can run following script from magento root directory, this scipt add attribute to customer and accessible in create customer and edit customer detail, example i have taken 'mobile' here so you can get that attribute using getMobile() method in edit customer and create customer page.... this script also automatically add and display in admin panel try these..

    define('MAGENTO', realpath(dirname(__FILE__)));
    
    require_once MAGENTO . '/app/Mage.php';
    
    Mage::app();
    
    
    
    $installer = new Mage_Customer_Model_Entity_Setup('core_setup');
    
    $installer->startSetup();
    
    $vCustomerEntityType = $installer->getEntityTypeId('customer');
    $vCustAttributeSetId = $installer->getDefaultAttributeSetId($vCustomerEntityType);
    $vCustAttributeGroupId = $installer->getDefaultAttributeGroupId($vCustomerEntityType, $vCustAttributeSetId);
    
    $installer->addAttribute('customer', 'mobile', array(
            'label' => 'Customer Mobile',
            'input' => 'text',
            'type'  => 'varchar',
            'forms' => array('customer_account_edit','customer_account_create','adminhtml_customer','checkout_register'),
            'required' => 0,
            'user_defined' => 1,
    ));
    
    $installer->addAttributeToGroup($vCustomerEntityType, $vCustAttributeSetId, $vCustAttributeGroupId, 'mobile', 0);
    
    $oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'mobile');
    $oAttribute->setData('used_in_forms', array('customer_account_edit','customer_account_create','adminhtml_customer','checkout_register'));
    $oAttribute->save();
    
    $installer->endSetup();
    

    Display attribute on Font End.

    add following code to edit.phtml file located at app/design/frontend/base/default/template/customer/form/edit.phtml

提交回复
热议问题