-1

I have tried to add a custom registration fields in magento 1.5 0. I tried to do that following Adding custom registration fields in magento 1.5 and many other way I've founded. But if i add any data during registration for the field it not saved to the table customer_entity_varchar and neither attribute added in table eav_attribute. This is my code :

In app/local/etc/modules/Mycustommodule_Customer.xml I have this :

<config>
    <modules>
        <Mycustommodule_Customer>
            <active>true</active>
            <codePool>local</codePool>
        </Mycustommodule_Customer>
    </modules>
</config>

In app/local/Mycustommodule/Customer/etc/config.xml this :

<?xml version="1.0"?>
<config>
    <modules>
        <Mycustommodule_Customer>
            <version>0.1.0</version>
        </Mycustommodule_Customer>
    </modules>
    <global> 
        <models>
            <Mycustommodule_Customer>
                <class>Mycustommodule_Customer_Model</class>
            </Mycustommodule_Customer>
        </models>
        <resources>
            <customerattribute_setup>
        <setup>
            <modules>Mycustommodule_Customer</modules>
            <class>Mycustommodule_Customer_Model_Entity_Setup</class>
        </setup>    
                <connection>
                    <use>core_setup</use>
                </connection>
            </customerattribute_setup>
            <customerattribute_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </customerattribute_write>
            <customerattribute_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </customerattribute_read>     
        </resources>
        <blocks>     
            <mycustommodule_customerattribute>
                <class>Mycustommodule_Customer_Block</class>
            </mycustommodule_customerattribute>    
        </blocks>       
        <helpers>
        <mycustommodule_customerattribute>
        <class>Mycustommodule_Customer_Helper</class>      
        </mycustommodule_customerattribute>
        </helpers>
        <fieldsets>
            <customer_account> 
                <phone><create>1</create><update>1</update></phone>
            </customer_account>
        </fieldsets>  
    </global>    
</config>

In app/local/Mycustommodule/Customer/Model/Entity/Setup.php this :

class Mycustommodule_Customer_Model_Entity_Setup  extends Mage_Customer_Model_Entity_Setup
{


    public function getDefaultEntities()
    {

        $defaultEntities = parent::getDefaultEntities();

        $defaultEntities['customer']['attributes']['phone'] = array(
                        'label'        => 'Phone Number',
                        'visible'      => 1,
                        'required'     => 1,
                        'position'     => 1,
                    );                           
        return $defaultEntities;
    }

}

In app/local/Mycustommodule/Customer/sql/customerattribute_setup/mysql4-install-0.1.0.php this :

$installer->startSetup();

$installer->addAttribute('customer','phone', array(
'label' => 'Phone Number',
'visible'   => 1,
'required'  => 1,
'position'  => 1,
));


$installer->endSetup();
// Get Customer Type ID
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
$eid = $read->fetchRow(
    "select entity_type_id from {$this->getTable('eav_entity_type')} where entity_type_code = 'customer'"
);
$customer_type_id = $eid['entity_type_id'];

// Save Attribute to the customer_form_attribute
$attribute = $eavConfig->getAttribute($customer_type_id, 'phone');

// Here is where you determine in wich areas of magento the attributes are used
$attribute->setData('used_in_forms', array('customer_account_edit', 'customer_account_create', 'adminhtml_customer'));
$attribute->save();

I added the filed into app/design/frontend/default/mycustommodule/template/customer/form/register.phtml and app/design/frontend/default/mycustommodule/template/customer/form/edit.phtml

What I did wrong or missed ???

Community
  • 1
  • 1
Teddy115
  • 1
  • 2
  • Where does that `$eavConfig` object come from? It's not defined anywhere in the code you posted. – Jürgen Thelen Jul 04 '12 at 10:50
  • oh that's probably the problem. I try. thx – Teddy115 Jul 04 '12 at 10:58
  • I add this $eavconfig = new Mage_Eav_Model_Entity_Setup('core_setup'); but it doesn't change anything. I still not have any value in customer_entity_varchar and neither in table eav_attribute regarding to "phone" – Teddy115 Jul 04 '12 at 11:30

1 Answers1

0

I hope the below link will helps you.

How to create new fields for customer

Only the view(.phtml) files path vary from 1.5 and 1.6+

Community
  • 1
  • 1
Sankar Subburaj
  • 4,992
  • 12
  • 48
  • 79
  • Thanks for your quick answer but what I suppose to see ?? I've also tried this solution : [link](http://www.magentocommerce.com/wiki/5_-_modules_and_development/customers_and_accounts/registration_fields) by adding this into register.phtml :$setup = new Mage_Eav_Model_Entity_Setup('core_setup'); $AttrCode = 'occupation'; $settings = array ( 'position' => 1, 'is_required'=> 0 ); $setup->addAttribute('1', $AttrCode, $settings); – Teddy115 Jul 04 '12 at 10:51