0

我想在客户帐户注册页面中添加另一个国家/地区下拉列表。我试过了

<?php echo $this->getCountryHtmlSelect() ?>

但这不显示下拉菜单。我试过的另一个是

<select name="partner_country" id="partner_country">
    <option value=''>– Please Select –&lt;/option>
        <?php foreach($_countries as $_country): ?>
            <option value="<?php echo $_country->getId() ?>"><?php echo $_country->getName() ?></option>
        <?php endforeach; ?>
</select>

这一项显示国家列表,但所选国家不显示在后端客户信息页面中。

我知道getCountryHtmlSelect()呈现国家/地区的下拉菜单。我是否在我的模块中创建了类似的方法来保存所选国家/地区?

更新

通过设置脚本添加此属性时,我已经创建了一个源模型,

$installer->addAttribute('customer_address','partner_country_id',array(
        'type'               => 'varchar',
        'label'              => 'Partner Country',
        'input'              => 'select',
        'source'             => 'wholesale/attribute_source_partnercountry',
        'global' => 1,
        'visible' => 1,
        'required' => 0,
        'visible_on_front' => 1,
        'sort_order'=>220
));

源模型

class Company_Wholesale_Model_Attribute_Source_Partnercountry extends Mage_Eav_Model_Entity_Attribute_Source_Table
{
    public function getAllOptions()
    {
        if (!$this->_options) {
            $this->_options = Mage::getResourceModel('directory/country_collection')
                ->loadByStore($this->getAttribute()->getStoreId())->toOptionArray();
        }
        return $this->_options;
    }

}

配置文件

<config>
    <global>
        <resources>
            <wholesale_setup>
                <setup>
                    <module>Company_Wholesale</module>
                    <class>Company_Wholesale_Model_Entity_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </wholesale_setup>
        </resources>
    </global>
</config>
4

2 回答 2

2

您遇到的问题与您创建的属性类型有关。为了在管理员中选择您的自定义属性,您需要使用“select”和“source_model”类型创建/更新它。为此需要使用客户模块设置模型,因此在设置资源的模块配置中,您需要指定它:

<config>
   <global>
       <resources>
           <your_module_setup>
               <setup>
                  <class>Mage_Customer_Model_Resource_Setup</class>
                  <module>Your_Module</module>
               </setup>
           </your_module_setup>
       </resources>
    </global>
</config>

在您的设置文件中,您需要创建/修改您的属性。(如果属性存在,当前代码片段将修改它,而不是创建)。

<?php

$this->startSetup();
$this->addAttribute('customer', 'partner_country' , array(
     'type'   => 'varchar',
     'label'  => 'Partner Country',
     'input'  => 'select',
     'source' => 'customer/entity_address_attribute_source_country'
));
$this->endSetup();

更新:

现在我收到了您的问题,您尚未将属性添加到客户创建帐户表单中,因此在帐户创建过程中从设置为客户模型的数据中过滤掉了您的属性。

因此,您只需为应该可以保存您的属性的表单指定您的客户属性。

目前有这样的表格可用:

  • customer_account_create - 注册表格
  • customer_account_edit - 更改帐户详细信息表格
  • checkout_register - 在结帐时注册新帐户

要将您的自定义属性添加到表单,只需再创建一个设置脚本,将带有表单代码的记录和您的属性 id 添加到名为的表中customer/form_attribute

<?php
$this->startSetup();
$attributeId = $this->getAttributeId('customer', 'partner_country_id');
$data = array(
    array('attribute_id' => $attributeId, 'form_code' => 'customer_account_create'),
    array('attribute_id' => $attributeId, 'form_code' => 'customer_account_edit'),
    array('attribute_id' => $attributeId, 'form_code' => 'checkout_register')
);
$this->getConnection()->insertMultiple($this->getTable('customer/form_attribute'), $data);
$this->endSetup();

只需选择退出您不需要的表格。

于 2012-07-23T07:00:35.670 回答
1

如果您想使用getCountryHtmlSelect(),那么您应该给它一些参数,以便它可以应用于您的属性,而不是country默认情况下。对于注册表单,它可以给出如下内容:

echo $this->getCountryHtmlSelect($this->getFormData()->getPartnerCountryId(), 'partner_country_id', 'partner_country', $this->__('Partner Country'))

在第二个示例中,您partner_country在选择名称中使用,而您创建了一个partner_country_id属性。

于 2012-07-23T08:17:21.113 回答