i am trying to add a couple of custom fields to the registration page. After going though various posts about this topic i tried to create a module for this. I see that my 2 custom fields are added to the eav_attribute and eav_entity_attribute tables. I also see that the entity_type_id is set to 1 which is customer for my entries. But if i add any data during registration for these fields its not saved to the table customer_entity_varchar . Here is my code: /etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Foostor_Extcustomerfields>
<version>0.1.0</version>
</Foostor_Extcustomerfields>
</modules>
<!-- <frontend>
<routers>
<pws_extshipping>
<use>standard</use>
<args>
<module>PWS_ExtShipping</module>
<frontName>pws_extshipping</frontName>
</args>
</pws_extshipping>
</routers>
<layout>
<updates>
<pws_extcustomerfields module="PWS_ExtCustomerFields">
<file>pws_extcustomerfields.xml</file>
</pws_extcustomerfields>
</updates>
</layout>
</frontend> -->
<global>
<models>
<foostor_extcustomerfields>
<class>Foostor_Extcustomerfields_Model</class>
</foostor_extcustomerfields>
</models>
<resources>
<foostor_extcustomerfields_setup>
<setup>
<module>Foostor_Extcustomerfields</module>
<class>Foostor_Extcustomerfields_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</foostor_extcustomerfields_setup>
<foostor_extcustomerfields_write>
<connection>
<use>core_write</use>
</connection>
</foostor_extcustomerfields_write>
<foostor_extcustomerfields_read>
<connection>
<use>core_read</use>
</connection>
</foostor_extcustomerfields_read>
</resources>
<blocks>
<foostor_extcustomerfields>
<class>Foostor_Extcustomerfields_Block</class>
</foostor_extcustomerfields>
</blocks>
<helpers>
<foostor_extcustomerfields>
<class>Foostor_Extcustomerfields_Helper</class>
</foostor_extcustomerfields>
</helpers>
<fieldsets>
<customer_account>
<registration_number><create>1</create><update>1</update></registration_number>
<registration_comment><create>1</create><update>1</update></registration_comment>
</customer_account>
</fieldsets>
</global>
</config>
/Model/Entity/Setup.php:
<?php
class Foostor_Extcustomerfields_Model_Entity_Setup extends Mage_Customer_Model_Entity_Setup
{
public function getDefaultEntities()
{
$defaultEntities = parent::getDefaultEntities();
$defaultEntities['customer']['attributes']['registration_number'] = array(
'label' => 'Company Registration Number',
'visible' => 1,
'required' => 1,
'position' => 1,
);
$defaultEntities['customer']['attributes']['registration_comment'] = array(
'label' => 'Comment',
'visible' => 1,
'input' => 'textarea',
'required' => 1,
'position' => 1,
);
return $defaultEntities;
}
}
/sql/foostor_extcustomerfields_setup/mysql4-install-0.1.0.php:
<?php
$installer = $this;
/* @var $installer PWS_ExtCustomerFields_Model_Entity_Setup */
$installer->startSetup();
$installer->addAttribute('customer', 'registration_number', array(
'label' => 'Company Registration Number',
'visible' => 1,
'required' => 1,
'position' => 1,
));
$installer->addAttribute('customer', 'registration_comment', array(
'label' => 'Comment',
'visible' => 1,
'input' => 'textarea',
'required' => 0,
'position' => 1,
));
$installer->endSetup();
I have added the required code to the register.phtml and edit.phtml file too to display the fields that i have added. What do i need to add to save the data from the additional fields to the database and be able to retrieve that data? Apologize for pasting the code here. Thanks.
You have also to register the attribute_id of new created attributes to the customer_form_attribute, so Magento knows where things are :-)
In your case you have to put this in your setup file: (Example taken form the Debit Payment Module)
// 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, 'registration_number');
// 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();
Hope this helps :-)
Or use this:
- Supports fields on Create Customer Account page
- Supports fields on Edit Customer Account page
- Supports fields on Checkout Registration page: standart onepage checkout - not a thirdparty onestep.
http://www.magentocommerce.com/magento-connect/catalog/product/view/id/16093/ http://www.magazento.com/english/magento-ext/magazento-extensions/custom-registration-filelds
来源:https://stackoverflow.com/questions/6993392/adding-custom-registration-fields-in-magento-1-5