magento 为用户注册增加一个字段

 

步骤 I. 加一个occupation/title字段到用户注册页,差不多在register.html54行,在email下方加一个Occupation显示代码

<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->

代码:

<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>

 

步骤 6: 最后需要在表customer_form_attribute表增加记录,将新增字段与customer的前台显示表格关联:

 

form code                               attribute_id

adminhtml_checkout              264

adminhtml_customer              264

checkout_register                       264

customer_account_create 264

customer_account_edit                264


Attribute_id 是指该属性在eav_attribute表的attribute_id

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值