-1

我曾尝试在 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.phtmlapp/design/frontend/default/mycustommodule/template/customer/form/edit.phtml

我做错了什么或错过了什么???

4

1 回答 1

0

我希望下面的链接对你有帮助。

如何为客户创建新字段

只有视图(.phtml)文件路径从 1.5 到 1.6+

于 2012-07-04T10:33:19.913 回答