2

i use magento 1.9.x, need in form register add next field: Username, Password, Confirm Password, Location, First Name, Last Name, Phone, how i can do this? i need also store in backend this filed in customer account admin, how in possible? can you help me solove this problem?

2

Base you need on this solution and customise it according to the fields that you want to add.

We will create a new extension to make it clean.

Let's call the extension StackExchange_Customer. You will need the following files:

1- app/etc/modules/StackExchange_Customer.xml

 

<?xml version="1.0"?>
<config>
    <modules>
        <StackExchange_Customer>
            <active>true</active>
            <codePool>local</codePool>
            <depends><Mage_Customer/></depends>
        </StackExchange_Customer>
    </modules>
</config> 

 

2- app/code/local/StackExchange/Customer/etc/config.xml

 

<?xml version="1.0"?>
<config>
    <modules>
        <StackExchange_Customer>
            <version>1.0.0</version>
        </StackExchange_Customer>
    </modules>
    <global>
        <helpers>
            <stackexchange_customer>
                <class>StackExchange_Customer_Helper</class>
            </stackexchange_customer>
        </helpers>
        <resources>
            <stackexchange_customer_setup>
                <setup>
                    <module>StackExchange_Customer</module>
                    <class>Mage_Customer_Model_Resource_Setup</class>
                </setup>
            </stackexchange_customer_setup>
        </resources>
    </global>
    <frontend>
        <layout>
            <updates>
                <stackexchange_customer>
                    <file>stackexchange_customer.xml</file>
                </stackexchange_customer>
            </updates>
        </layout>
        <translate>
            <modules>
                <StackExchange_Customer>
                    <files>
                        <default>StackExchange_Customer.csv</default>
                    </files>
                </StackExchange_Customer>
            </modules>
        </translate>
    </frontend>
</config>

 

3- app/code/local/StackExchange/Customer/sql/stackexchange_customer_setup/install-1.0.0.php

 

<?php
$this->addAttribute('customer', 'license_number', array(
    'type'      => 'varchar',
    'label'     => 'License Number',
    'input'     => 'text',
    'position'  => 120,
    'required'  => false,//or true
    'is_system' => 0,
));
$attribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'license_number');
$attribute->setData('used_in_forms', array(
    'adminhtml_customer',
    'checkout_register',
    'customer_account_create',
    'customer_account_edit',
));
$attribute->setData('is_user_defined', 0);
$attribute->save();

 

4- app/code/local/StackExchange/Customer/Helper/Data.php

 

<?php
class StackExchange_Customer_Helper_Data extends Mage_Core_Helper_Abstract
{

}

This will add your attribute for the customer in admin, and now we have to edit the frontend templates to add the field to the customer.

 

5- app/design/frontend/base/default/layout/stackexchange_customer.xml

 

<?xml version="1.0"?>
<layout>
    <customer_account_edit>
        <reference name="customer_edit">
            <action method="setTemplate">
                <template>stackexchange_customer/form/edit.phtml</template>
            </action>
        </reference>
    </customer_account_edit>
    <customer_account_create>
        <reference name="customer_form_register">
            <action method="setTemplate">
                <template>stackexchange_customer/register.phtml</template>
            </action>
        </reference>
    </customer_account_create>
</layout>

 

6- app/design/frontend/base/default/template/stackexchange_customer/register.phtml

  For this one make a clone of the /app/design/frontend/{package}/{theme}/template/persistent/customer/form/register.phtml and just insert this somewhere inside the form. I don't need to post the full file here. Arrange it as you please

<li>
    <label for="license_number"><?php echo $this->__('License Number') ?></label>
    <div class="input-box">
        <input type="text" name="license_number" id="license_number" value="<?php echo $this->escapeHtml($this->getFormData()->getLicenseNumber()) ?>" title="<?php echo $this->__('License Number') ?>" class="input-text" />
    </div>
</li>

 

7- app/design/frontend/base/default/template/stackexchange_customer/form/edit.phtml

For this one clone /app/design/frontend/{package}/{theme}/template/customer/form/edit.phtml and insert somewhere inside the form this:

<li>
    <label for="license_number"><?php echo $this->__('License Number') ?></label>
    <div class="input-box">
        <input type="text" name="license_number" id="license_number" value="<?php echo $this->htmlEscape($this->getCustomer()->getLicenseNumber()) ?>" title="<?php echo $this->__('License Number') ?>" class="input-text" />
    </div>
</li>

 

8- app/locale/en_US/StackExchange_Customer.csv

 

"License Number","License Number"

 

Clear the cache and enjoy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.