閱讀793 返回首頁    go 阿裏雲 go 技術社區[雲棲]


為Magento1.5新增會員注冊字段

第一步、新建一個模塊,在app/etc/modules/目錄下新建文件Shuishui_Customer.xml

<config>
    <modules>
        <Shuishui_Customer>
            <active>true</active>
            <codePool>community</codePool>
        </Shuishui_Customer>
    </modules>
</config>
第二步、新建這個模塊的config配置文件,位置在app/code/community/Shuishui/Customer/etc/config.xml

<?xml version="1.0"?>

<config>
    <modules>
        <Shuishui_Customer>
            <version>0.1.0</version>
        </Shuishui_Customer>
    </modules>
    <global>
    <fieldsets>
        <customer_account>
              <mobile><create>1</create><update>1</update></mobile>
        </customer_account>
    </fieldsets>
        <models>
            <Shuishui_Customer>
                <class>Shuishui_Customer_Model</class>
            </Shuishui_Customer>
        </models>
        <helpers>
            <Shuishui_Customer>
                <class>Shuishui_Customer_Helper</class>
            </Shuishui_Customer>
        </helpers>
        <resources>
            <customerattribute_setup>
                <setup>
                    <module>Shuishui_Customer</module>
                    <class>Shuishui_Customer_Model_Entity_Setup</class>
                </setup>
            </customerattribute_setup>
        </resources>
    </global>
  

 
    
</config>
第三步、新建一個model類,繼承自Mage_Customer_Model_Entity_Setup類,類裏新添加一個字段,位置在app/code/community/Shuishui/Customer/Model/Entity/Setup.php

class Fanxiang_Customer_Model_Entity_Setup extends Mage_Customer_Model_Entity_Setup
'created_at' => array(
                        'type'          => 'static',
                        'label'         => 'Created At',
                        'visible'       => false,
                        'required'      => false,
                        'input'         => 'date',
                    ),
                    'mobile' => array(
                        'type'          => 'static',
                        'label'         => 'Mobile',
                        'visible'       => true,
                        'required'      => false,
                        'sort_order'    => 80,
                    ),
                ),
            ),

            'customer_address'=>array(
                'entity_model'  =>'customer/customer_address',
                'table' => 'customer/address_entity',
                'additional_attribute_table' => 'customer/eav_attribute',
                'entity_attribute_collection' => 'customer/address_attribute_collection',

第四步、新增一個數據庫安裝腳本文件,位置在app/code/community/Shuishui/Customer/sql/customerattribute_setup/mysql4-install-0.1.0.php

$installer = $this;

$installer->startSetup();

$installer->addAttribute('customer','mobile',array(
      'label' => 'Mobile',
      'visible'=>1,
      'required'=>0,
      'position'=>1,
      'sort_order'=>80,
    
));

$installer->endSetup();

$customerattribute = Mage::getModel('customer/attribute')->loadByCode('customer','mobile');
$forms = array('customer_account_edit','customer_account_create','adminhtml_customer','checkout_register');
$customerattribute->setData('used_in_forms',$forms);
$customerattribute->save();
第五步,在前台注冊頁麵的模板文件中添加一個新的表單項,位置在template\customer\form\register.phtml

<li>
                    <label for="mobile" ><em>*</em><?php echo $this->__('mobile') ?></label>
                    <div >
                        <input type="text" name="mobile"  value="" title="<?php echo $this->__('mobile') ?>"  />
                    </div>
                </li>
前台顯示效果



後台會員管理頁麵效果



PS:1.4版本同樣適用

參見原文:https://mydons.com/how-to-add-custom-fields-to-customer-registration-and-account-page-in-magento-1-5/


最後更新:2017-04-02 06:52:03

  上一篇:go Android字符串資源及其格式化
  下一篇:go JAVA編程思想第四版—第二章—習題與答案