How to add custom fields in magento

本文介绍如何在Magento中扩展默认客户注册表单,通过创建自定义模块来增加额外字段,如手机号等,并提供详细步骤及兼容性说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Magento Provides the default customer registration form with very few fields like name,email,pwd etc. But in realtime we need to get more details from the customer during registration. In order to achieve this we may have to create custom module that extends the magento customer module.

Step 1: We Start with Our module activation file first it just specifies the module name its location and Active Status. This file must be placed in app/etc/modules/ directory as app/etc/modules/Mydons_Customer.xml

Step 2: Next we need to create our config.xml file. Here we specify the model class name of our module. Then in the global tag we specify our custom field for our customer. Here iam creating a custom field called mobile.
Our config.xml should be placed in the directory app/code/local/Mydons/Customer/etc/config.xml


Under the resources tag I have added the customer setup class name. The only model class available in this module is Mydons_Customer_Model_Entity_Setup. This class is a subclass of Mage_Customer_Model_Entity_Setup class.

Step 3: Now We need to create a Model Class we specified in the Previous step. This class contains only a single method called getDefaultEntities. You can copy the getDefaultEntities Method from the Base class Mage_Customer_Model_Entity_Setup and paste it in our model class Mydons_Customer_Model_Entity_Setup. This File must reside in our Model directory app/code/local/Mydons/Customer/Model/Entity/Setup.php

Step 4: We are going to add our custom field mobile in the customer array of the getDefaultEntities Method as shown below

Step 5: In Our Final Step we need to create our setup file which is a install script in the directory app/code/local/Mydons_Customer/sql/customerattribute_setup/mysql4-install-0.1.0.php

Here in the first part i have added the customer attribute to EAV table with attribute Properties. For Magento version 1.3 this part alone is enough to make the custom field save to the database. However for latest versions like Magento 1.4 and 1.5 we need an additional step to save in Customer Attribute table. First we get the Eav attribute using its attribute code and then we need to Set in which forms the custom field is going to be used.
After this Step we can add our custom field in the register and account edit template files. The custom field will now be saved to the database.

Compatability : Magento 1.4 and Magento 1.5

http://mydons.com/category/framework/magento/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值