I managed to add a field to the registration page and have it saved to the database. thanks to the help of this tutorial. I have added my code which has done the job.
Sorry there is no explanation to the code or an answer to what is customer_account_edit
and customer_account_create
and how is setData() parameter decided. But I thought this code may be helpful for anyone else adding new fields. Hopefully someone with more knowledge will expand on that part
config.xml
<global>
<fieldsets>
<customer_account>
<username>
<create>1</create>
<update>1</update>
<name>1</name>
</username>
</customer_account>
</fieldsets>
<resources>
<customforms_reginfo_setup>
<setup>
<module>Customforms_Reginfo</module>
<class>Mage_Customer_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</customforms_reginfo_setup>
</resources>
</global>
setup-0.1.0.php
$installer = $this;
$installer->startSetup();
$this->addAttribute('customer', 'username', array(
'type' => 'varchar',
'input' => 'text',
'label' => 'Username',
'global' => 1,
'visible' => 1,
'required' => 1,
'user_defined' => 1,
'visible_on_front' => 1
));
Mage::getSingleton('eav/config')
->getAttribute('customer', 'username')
->setData('used_in_forms', array('adminhtml_customer', 'customer_account_edit','customer_account_create'))
->save();
$installer->endSetup();
Try it like this:
->addForeignKey(
$installer->getFkName('namespace_module/shop', 'area_id', 'namespace_module/area','area_id'),
'area_id',
$installer->getTable('namespace_module/area'),
'area_id',
Varien_Db_Ddl_Table::ACTION_CASCADE,
Varien_Db_Ddl_Table::ACTION_CASCADE
)
The difference in my code is that I removed the first line below getFkName
.
since you are calling addForeignKey
on a table while creating it, you don't need to specify it's name again.
as a general rule use:
->addForeignKey(
$installer->getFkName('TABLE ALIAS', 'FK_FIELD', 'REF_TABLE_ALIAS','REF_TABLE_FIELD'),
'CURRENT_TABLE_FIELD_NAME',
$installer->getTable('REF_TABLE_ALIAS'),
'REF_TABLE_FIELD',
Varien_Db_Ddl_Table::ACTION_CASCADE,
Varien_Db_Ddl_Table::ACTION_CASCADE
)
[Edit]
You should be looking at Varien_Db_Ddl_Table::addForeignKey
because you are using it on an instance of Varien_Db_Ddl_Table
.
Best Answer
The base setup classes for
flat tables
areMage_Core_Model_Resource_Setup
and EAV entitiesMage_Eav_Model_Entity_Setup
.Mage_Core_Model_Resource_Setup
is used for non eav module and report and product alert admin modules table creation and it work on single tableMage_Eav_Model_Entity_Setup
is eav structural module. for customer ,product ,category module table creation and it work on multiple tableSee at http://alanstorm.com/magento_advanced_orm_entity_attribute_value_part_1