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