码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-09-12 19:06:03      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

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

代码:
<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>

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

标签:

原文地址:http://www.cnblogs.com/xingmeng/p/4803379.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!