我曾尝试在 magento 1.5 0 中添加自定义注册字段。我尝试按照在 magento 1.5 中添加自定义注册字段以及我创建的许多其他方式来执行此操作。但是,如果我在注册期间为该字段添加任何数据,它不会保存到表 customer_entity_varchar 中,也没有在表 eav_attribute 中添加任何属性。这是我的代码:
在app/local/etc/modules/Mycustommodule_Customer.xml
我有这个:
<config>
<modules>
<Mycustommodule_Customer>
<active>true</active>
<codePool>local</codePool>
</Mycustommodule_Customer>
</modules>
</config>
在app/local/Mycustommodule/Customer/etc/config.xml
这个:
<?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>
在app/local/Mycustommodule/Customer/Model/Entity/Setup.php
这个:
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;
}
}
在app/local/Mycustommodule/Customer/sql/customerattribute_setup/mysql4-install-0.1.0.php
这个:
$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();
我将文件添加到app/design/frontend/default/mycustommodule/template/customer/form/register.phtml
和app/design/frontend/default/mycustommodule/template/customer/form/edit.phtml
我做错了什么或错过了什么???