0
votes

I created a custom module to add Land Phone field in registration page. The form display the field but in database the Land Phone number is not inserted. But in eav_attribute table the landphone attribute is added. The only issue is the value of Land Phone is not inserted in customer table. I followed this tutorial: http://www.fontis.com.au/blog/magento/know-more-about-your-customers-adding-custom-signup-attributes

I will give you the detailed code what i did.

My module name is TCreg_Customer

app/etc/modules/TCreg_Customer.xml

<?xml version="1.0"?>
<config>
    <modules>
        <TCreg_Customer>
        <codePool>local</codePool>
        <active>true</active>
        </TCreg_Customer>
    </modules>
</config>

app/code/local/TCreg/Customer/etc/config.xml

I copy app/code/core/Mage/Customer/etc/config.xml file and make 2 changes

<modules>
        <TCreg_Customer>
            <version>1.0.0</version>
        </TCreg_Customer>
    </modules>

and add

<landphone><create>1</create><update>1</update></landphone>

inside <customer_account> tag

app/code/local/TCreg/Customer/Model/Entity/Setup.php

<?php
class TCreg_Customer_Model_Entity_Setup extends Mage_Customer_Model_Entity_Setup
{
    public function getDefaultEntities(){

        return array(

                'landphone'=>array(
                        'type'=> 'varchar',
                        'label'=> 'Land Phone',
                        'visiable' => true,
                        'sort_order' => 80,
                )
        );
    }
} 
?>

The Land Phone field is set in register.phtml located in app/design/frontend/mytheme/template/persistent/customer/form/register.phtml

<!--landphone field begin-->
    <div class="field">
     <label for="landphone"><?php echo $this->__('Land Phone') ?></label>
     <div class="input-box">
     <input type="text" name="landphone" id="landphone" value="<?php echo $this->escapeHtml($this->getFormData()->getLandphone()) ?>" title="<?php echo $this->__('Land Phone') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('landphone') ?>" />
   </div>
</div>
<!--landphone field end-->

app/design/frontend/mytheme/template/persistent/customer/address/edit.phtml

<!--Landphone field begin-->
    <div class="field">
    <label for="landphone"><?php echo $this->__('Land Phone') ?></label>
     <div class="input-box">
     <input type="text" name="landphone" value="<?php echo $this->htmlEscape($this->getAddress()->getLandphone()) ?>" title="<?php echo $this->__('Land Phone') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('landphone') ?>" id="landphone" />

</div>
</div>
<!--Landphone field end-->

The new attribute (land phone) needs to be added to the Magento database. So I added these bit of code in register.phtml

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('customer', 'landphone', array(
    'label'     => 'Land Phone',
    'type'      => 'varchar',
    'input'     => 'text',
    'visible'   => true,
    'position'  => 1,
    ));

I think the only issue is the value of Land phone is not inserted in customer table. But I can't find the solution. So please help me .. How can I solve this?? Any help is really appreciable..

My magento version is 1.9.1.0

1
Have a look at the following post for the same purpose :phpmagento.blogspot.in/2012/02/… Hope you will get some idea to do this in another way...Don't forgot copy the core files in to the Local code pool folder - Vinod Kumar
@VinodKumar, what is it?? 'Don't forgot copy the core files in to the Local code pool folder'.. - Deepu Sasidharan
The link that I referred to you, is showing all code modification in core files directly...so I suggested you to copy all files that you will edit, into the local/Mage directory... - Vinod Kumar
@VinodKumar, I followed the tutorial, but no luck..still the data is not inserted into the table. - Deepu Sasidharan

1 Answers

0
votes

You will need to make sure that the attribute has an entry in the table customer_form_attribute this will tell Magento what customer attributes should be available on each customer and address forms.

You can do this by the following script snippet. Build a new set-up script, that you have already mentioned that you can do and set an array of all forms that the attribute needs to be available in.

Mage::getSingleton('eav/config')
        ->getAttribute('customer', 'attribute_code')
        ->setData('used_in_forms', array('adminhtml_customer', 'checkout_register', 'customer_account_create'))
        ->save();

The form code options are as follows:

  • adminhtml_checkout,
  • adminhtml_customer,
  • adminhtml_customer_address,
  • checkout_register,
  • customer_account_create,
  • customer_account_edit,
  • customer_address_edit,
  • customer_register_address