2012-07-18 54 views
0

我想添加在客户账户的国家的另一个下拉列表登记page.I试图Magento的保存选定国家

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

但这并不显示dropdown.Another一个我想是

<select name="partner_country" id="partner_country"> 
    <option value=''>– Please Select –</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.xml中

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

回答

1

如果你想使用getCountryHtmlSelect(),那么你应该给它一些参数,以便它可以应用于你的属性,而不是默认的country。对于登记表,它可以给这样的事情:

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

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

+0

感谢@bImage的输入 – blakcaps 2012-07-23 09:21:57

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(); 

刚刚退出的形式,你不需要。

+0

感谢您的指点。但我已经创建了你所说的话。更新了我的问题。 – blakcaps 2012-07-23 07:18:33

+0

@blakcaps查看我更新的答案。 – 2012-07-23 08:41:59

+0

感谢您的输入以及 – blakcaps 2012-07-23 09:22:24