如何在magento注册页面中显示自定义字段?

时间:2012-07-23 11:06:17

标签: magento

我是magento的新手。我创建了一个自定义模块,它应该将自定义字段添加到客户注册页面。我已经成功地向客户添加了一个自定义字段,我可以在编辑客户或添加新客户时在管理员/客户上看到。我如何才能在注册页面上显示它?

这是我模块的安装文件:

mysql4安装-0.1.0.php

<?php
$installer = $this;
$installer->startSetup();

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$entityTypeId     = $setup->getEntityTypeId('customer');
$attributeSetId   = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

$setup->addAttribute('customer', 'resale', array(
    'input'         => 'text',
    'type'          => 'varchar',
    'label'         => 'Resale number',
    'visible'       => 1,
    'required'      => 1,
    'user_defined' => 1,
));

$setup->addAttributeToGroup(
 $entityTypeId,
 $attributeSetId,
 $attributeGroupId,
 'resale',
 '999'  //sort_order
);

$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'resale');
$oAttribute->setData('used_in_forms', array('adminhtml_customer','customer_account_create'));
$oAttribute->save();

$installer->endSetup();

谢谢。

1 个答案:

答案 0 :(得分:1)

您应该向register.html添加代码,如下所示:

<div class="field">
  <label for="my_attribute" class="required"><em>*</em><?php echo $this->__('My Attribute') ?></label>
  <div class="input-box">
    <input type="text" name="my_attribute" id="my_attribute" value="<?php echo $this->htmlEscape($this->getFormData()->getMyAttribute()) ?>" title="<?php echo $this->__('My Attribute') ?>" class="input-text required-entry" />
  </div>
</div>
相关问题