我正在尝试在 Magento 客户注册页面上进行组选择下拉菜单。我已经完成了以下所有操作:
将以下代码插入到 template/persistent/customer/form/register.phtml 中:
<label for="group_id" style='margin-top:15px;'><?php echo $this->__('Which group do you belong to? (select "Pet Owner" if you are uncertain)') ?><span class="required">*</span></label>
<div style='clear:both'><p style='color:red;'>Note: DVM/DACVO and Institution accounts require administrative approval.</p></div>
<div class="input-box" style='margin-bottom:10px;'>
<select style='border:1px solid gray;' name="group_id" id="group_id" title="<?php echo $this->__('Group') ?>" class="validate-group required-entry input-text" />
<?php $groups = Mage::helper('customer')->getGroups()->toOptionArray(); ?>
<?php foreach($groups as $group){ ?>
<?php if ($group['label']=="Pet Owner" || $group['label']=="DVM / DACVO" || $group['label']=="Institution"){?>
<option value="<?php print $group['value'] ?>"><?php print $group['label'] ?></option>
<?php } ?>
<?php } ?>
</select>
</div>
然后在 createPostAction() 中的 /app/code/local/Mage/Customer/controllers/AccountController.php 中执行以下操作:
$customer->setGroupId($this->getRequest()->getPost(‘group_id’));
最后在添加组 ID 的 /app/code/local/Mage/Customer/etc/config.xml 中添加以下内容:
<fieldsets>
<customer_account>
<prefix>
<create>1</create>
<update>1</update>
<name>1</name>
</prefix>
<firstname>
<create>1</create>
<update>1</update>
<name>1</name>
</firstname>
<middlename>
<create>1</create>
<update>1</update>
<name>1</name>
</middlename>
<lastname>
<create>1</create>
<update>1</update>
<name>1</name>
</lastname>
<suffix>
<create>1</create>
<update>1</update>
<name>1</name>
</suffix>
<email>
<create>1</create>
<update>1</update>
</email>
<password>
<create>1</create>
</password>
<confirmation>
<create>1</create>
</confirmation>
<dob>
<create>1</create>
<update>1</update>
</dob>
<group_id><create>1</create><update>1</update></group_id>
<taxvat>
<create>1</create>
<update>1</update>
</taxvat>
<gender>
<create>1</create>
<update>1</update>
</gender>
</customer_account>
我已经对其进行了多次测试,每个客户仍被添加为默认客户组。你能看到我做错了什么吗?