magento 为用户注册增加一个字段(转)
2015-09-12 18:25
225 查看
步骤 I. 加一个occupation/title字段到用户注册页,差不多在register.html的54行,在email下方加一个Occupation显示代码
代码:
这是,如果进入用户注册页, 就会看到新增的字段。
步骤 2 同样在edit.phtml中,加入Occupation显示块
代码:
步骤 3, 打开Model/Entity/Setup.php差不多在93行,email的下方,加入occupation的相关代码:
代码:
步骤4: 现在,代码就基本写好了 , 但是我们仍然需要执行一个数据库操作将occupation这个属性加入到eav_attribute表,把下面的代码块:
代码:
放到合适的文件里执行一次。我建议把它放到register.html文件的顶部,然后重新访问register.html.查看数据库eav_attribute表就能看到新增的条目。然后把上面的代码从register.phtml中移除。
步骤 5: 最后需要编辑app/code/core/Mage/Customer/etc/config.xml 的<fieldsets>标签下声明该字段如何处理插入和贵呢更新
代码:
代码:
<li> <div class="input-box"> <label for="email_address"><?php echo $this->__('Email Address') ?> <span class="required">*</span></label><br/> <input type="text" name="email" id="email_address" value="<?php echo $this->htmlEscape($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="validate-email required-entry input-text" /> </div> <div class="input-box"> <label for="occupation"><?php echo $this->__('Occupation/Title') ?></label><br/> <input type="text" name="occupation" id="occupation" value="<?php echo $this->htmlEscape($this->getFormData()->getOccupation()) ?>" title="<?php echo $this->__('Occupation') ?>" class="input-text" /> </div> </li>
这是,如果进入用户注册页, 就会看到新增的字段。
步骤 2 同样在edit.phtml中,加入Occupation显示块
代码:
<li> <div class="input-box"> <label for="email"><?php echo $this->__('Email Address') ?> <span class="required">*</span></label><br /> <input type="text" name="email" id="email" value="<?php echo $this->htmlEscape($this->getCustomer()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="required-entry validate-email input-text" /> </div> </li> <li> <div class="input-box"> <label for="occupation"><?php echo $this->__('Occupation') ?> </label><br/> <input type="text" name="occupation" id="occupation" value="<?php echo $this->htmlEscape($this->getCustomer()->getOccupation()) ?>" title="<?php echo $this->__('Occupation') ?>" class="input-text" /> </div> </li>
步骤 3, 打开Model/Entity/Setup.php差不多在93行,email的下方,加入occupation的相关代码:
代码:
'email' => array( 'type' => 'static', 'label' => 'Email', 'class' => 'validate-email', 'sort_order' => 60, ), 'occupation' => array( 'label' => 'Occupation', 'required' => false, 'sort_order' => 65, ),
步骤4: 现在,代码就基本写好了 , 但是我们仍然需要执行一个数据库操作将occupation这个属性加入到eav_attribute表,把下面的代码块:
代码:
<?php $setup = new Mage_Eav_Model_Entity_Setup('core_setup'); $AttrCode = 'occupation'; $settings = array ( 'position' => 1, 'is_required'=> 0 ); $setup->addAttribute('1', $AttrCode, $settings); ?>
放到合适的文件里执行一次。我建议把它放到register.html文件的顶部,然后重新访问register.html.查看数据库eav_attribute表就能看到新增的条目。然后把上面的代码从register.phtml中移除。
步骤 5: 最后需要编辑app/code/core/Mage/Customer/etc/config.xml 的<fieldsets>标签下声明该字段如何处理插入和贵呢更新
代码:
<fieldsets> <customer_account> ..... <occupation><create>1</create><update>1</update></occupation> </customer_account> </fieldsets>
相关文章推荐
- POJ 1776 - Task Sequences(哈密顿图)
- 泛型的剖解
- TI推出SimpleLink低能耗蓝牙CC2541
- TI推出SimpleLink低能耗蓝牙CC2541
- 为Magento1.5新增会员注册字段(转)
- Jmeter 快速入门教程(三-3) -- 使用参数化
- nyoj 170 网络的可靠性
- Spring+Quartz 集群(含提示序列化错误)
- 图片的base64编解码
- 20150912-maven安装
- Pentest - Mimikatz
- 配置NFS服务
- SimpleWiFi模块评估板
- ORA-01033:oracle初始化或者关闭错误
- MongoDB学习笔记<两>
- SimpleWiFi模块评估板
- source insight 里查看开源代码中文乱码的问题
- 使用ImageIO来获取图片宽高度
- R语言:网页抓取之get the data
- Genymotion模拟器无法打开解决方法