2012-07-18 89 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