注册表格 - Magento 中作为单选按钮的前缀

Registration Form - Prefix as radio buttons in Magento

如何更改单选按钮中的默认 PrefixOptions。默认代码在 app/design/frontend/base/default/template/customer/widget/name.phtml 中,前缀代码是:

<?php if ($this->showPrefix()): ?>
    <div class="field name-prefix">
        <label for="<?php echo $this->getFieldId('prefix')?>"<?php if ($this->isPrefixRequired()) echo ' class="required"' ?>><?php if ($this->isPrefixRequired()) echo '<em>*</em>' ?><?php echo $this->getStoreLabel('prefix') ?></label>
        <div class="input-box">
            <?php if ($this->getPrefixOptions() === false): ?>
                <input type="text" id="<?php echo $this->getFieldId('prefix')?>" name="<?php echo $this->getFieldName('prefix')?>" value="<?php echo $this->escapeHtml($this->getObject()->getPrefix()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->getStoreLabel('prefix')) ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('prefix') ?>" <?php echo $this->getFieldParams() ?> />
            <?php else: ?>
                <select id="<?php echo $this->getFieldId('prefix')?>" name="<?php echo $this->getFieldName('prefix')?>" title="<?php echo Mage::helper('core')->quoteEscape($this->getStoreLabel('prefix')) ?>" class="<?php echo $this->helper('customer/address')->getAttributeValidationClass('prefix') ?>" <?php echo $this->getFieldParams() ?>>
                <?php foreach ($this->getPrefixOptions() as $_option): ?>
                    <option value="<?php echo $_option?>"<?php if ($this->getObject()->getPrefix()==$_option):?> selected="selected"<?php endif; ?>><?php echo $this->__($_option)?></option>
                <?php endforeach; ?>
                </select>
            <?php endif; ?>
        </div>
    </div>
<?php endif; ?>

编辑基本布局不是一个好主意,因为任何更改都将在下一次 Magento 更新后消失。 您首先需要将此文件复制到您自己的主题中,即。 e. app/design/frontend/default/[your theme]/template/customer/widget/name.phtml.

之后您可以将此代码更改为以下内容:

<?php if ($this->showPrefix()): ?>
    <div class="field name-prefix">
        <label for="<?php echo $this->getFieldId('prefix')?>"<?php if ($this->isPrefixRequired()) echo ' class="required"' ?>><?php if ($this->isPrefixRequired()) echo '<em>*</em>' ?><?php echo $this->getStoreLabel('prefix') ?></label>
        <div class="input-box">
            <?php if ($this->getPrefixOptions() === false): ?>
                <input type="text" id="<?php echo $this->getFieldId('prefix')?>" name="<?php echo $this->getFieldName('prefix')?>" value="<?php echo $this->escapeHtml($this->getObject()->getPrefix()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->getStoreLabel('prefix')) ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('prefix') ?>" <?php echo $this->getFieldParams() ?> />
            <?php else: ?>
                <!--<select id="<?php echo $this->getFieldId('prefix')?>" name="<?php echo $this->getFieldName('prefix')?>" title="<?php echo Mage::helper('core')->quoteEscape($this->getStoreLabel('prefix')) ?>" class="<?php echo $this->helper('customer/address')->getAttributeValidationClass('prefix') ?>" <?php echo $this->getFieldParams() ?>>-->
                <?php foreach ($this->getPrefixOptions() as $_option): ?>
                    <?php if(empty($_option)) continue; ?>
                    <!--<option value="<?php echo $_option?>"<?php if ($this->getObject()->getPrefix()==$_option):?> selected="selected"<?php endif; ?>><?php echo $this->__($_option)?></option>-->
                    <input type="radio" value="<?php echo $_option?>" <?php if ($this->getObject()->getSuffix()==$_option):?> checked="checked"<?php endif; ?> name="<?php echo $this->getFieldName('prefix')?>"/> <?php echo $this->__($_option)?>
                <?php endforeach; ?>
                <!--</select>-->
            <?php endif; ?>
        </div>
    </div>
<?php endif; ?>

我只是评论了您不再需要的旧行(select 元素),但留下来供参考。