Wednesday, 3 July 2013

Magento Customer Custom Attributes


1 -  Write this code in your file for first time after refresh your browser remove the bellow code as well

// This is for Text box
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('customer', 'profile_url', array(
        'type'              => 'varchar',
        'backend'           => '',
        'frontend'          => '',
        'label'             => 'Profile Url',
        'input'             => 'text',
        'class'             => '',
        'source'            => '',
        'visible'           => true,
        'required'          => true,
        'user_defined'      => false,
        'default'           => '',
        'searchable'        => true,
        'filterable'        => false,
        'comparable'        => false,
        'visible_on_front'  => true,
        'unique'            => true,
'global' => 1
    ));



2 - Add filed in your customer registration page by using the column name for save the data. like the following


<li>
                <label for="profile_url">Profile Url</label>
                <input type="text" id="profile_url" name="profile_url" class="input-text required-entry" onchange="ChkName('<?php echo $path;?>',this.value)"/>
<span id="msgbox" class="validation-advice" style="display:none;"></span>
            </li>



3) Please have a look of the  "eav_attribute" table from your database table
see there your column is inserted or not.
Find/copy the attribute_id from the  "eav_attribute" table

4) Go to "customer_form_attribute" table and 
insert the following data

form_code = adminhtml_customer
attribute_id = "eav_attribute" table's attribute_id column   value


Then it will show in the bakend as well.

No need to write more code and edit the core file.


No comments:

Post a Comment

Thanks for your comments.