我正在尝试向注册页面添加几个自定义字段。在浏览了关于这个主题的各种帖子后,我试图为此创建一个模块。我看到我的2个自定义字段被添加到eav_attribute和eav_entity_attribute表中。我还看到entity_type_id设置为1,这是我的条目的客户。但是,如果我在注册这些字段期间添加任何数据,则不会将其保存到表customer_entity_varchar中。这是我的代码: /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();
我已将所需的代码添加到register.phtml和edit.phtml文件中,以显示我添加的字段。我需要添加什么来将数据从附加字段保存到数据库并能够检索该数据?为此处粘贴代码道歉。感谢。
答案 0 :(得分:4)
您还必须将新创建的属性的 attribute_id 注册到 customer_form_attribute ,以便Magento知道事情的位置: - )
在您的情况下,您必须将其放入您的设置文件中:(从借记卡付款模块中获取的示例)
// 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();
希望这会有所帮助: - )
答案 1 :(得分:0)
或者使用它:
http://www.magentocommerce.com/magento-connect/catalog/product/view/id/16093/ http://www.magazento.com/english/magento-ext/magazento-extensions/custom-registration-filelds