我想添加一些自定義字段到註冊頁面。通過關於這個話題的各種帖子後,我試圖爲此創建一個模塊。我看到我的2個自定義字段被添加到eav_attribute和eav_entity_attribute表中。我還看到entity_type_id設置爲1,這是我的條目的客戶。但是,如果我在這些字段的註冊過程中添加任何數據,它不會保存到customer_entity_varchar表中。這裏是我的代碼: /etc/config.xml在magento 1.5中添加自定義註冊字段
<?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文件也顯示,我已經添加的字段。我需要添加什麼來將附加字段中的數據保存到數據庫並能夠檢索該數據?道歉在這裏粘貼代碼。謝謝。
只是要清楚,我必須添加類似的代碼來註冊arrtibute_id到我Setup.php文件或mysql4安裝-0.1.0.php文件?謝謝。 – Nithin
與安裝文件我的意思是mysql4-install-0.1.0.php :-) – tecmec
謝謝了。這幫助了我。 – Nithin