2011-12-16 28 views
0

我想在管理配置中的多選字段中加載客戶屬性。 我得到的屬性,但只獲得他們每個人的首字母而不是全文。這是我的代碼,多選字段不能正確加載值 - Magento

public function toOptionArray() 
{ 
    $result = array(); 
    $addressAttributes = Mage::getModel('customer/entity_address_attribute_collection');  
    foreach ($addressAttributes as $addressAttribute) 
    {   
     if (($addressLabel = $addressAttribute->getFrontendLabel())) 
     $result[$addressAttribute->getId()] = $addressLabel; 
    } 
return $result; 
} 

,這是我的system.xml代碼

<fields> 
    <attributes> 
     <label>Attributes</label> 
     <frontend_type>multiselect</frontend_type> 
     <source_model>customerattributes/attributes</source_model> 
     <can_be_empty>1</can_be_empty> 
     <sort_order>1</sort_order> 
     <show_in_default>1</show_in_default> 
     <show_in_website>1</show_in_website> 
     <show_in_store>1</show_in_store>      
    </attributes> 
</fields>  

在這個任何想法?

回答

0

來源模型通常是有用的,當toOptionArray()返回以下格式的數組:

<select ... > 
    <option value="value1">First label to Display</option> 
    <option value="value2">Second label to Display</option> 
</select> 

或許,如果你改變你的函數:

array (
     array("label" => "First label to Display", "value" => "value1"), 
     array("label" => "Second label to Display", "value" => "value2"), 
); 

如下上面會呈現以下,你會看到你想要的:

public function toOptionArray() 
{ 
    $result = array(); 
    $addressAttributes = Mage::getModel('customer/entity_address_attribute_collection'); 
    foreach ($addressAttributes as $addressAttribute) 
    { 
     if (($addressLabel = $addressAttribute->getFrontendLabel())) 
      $result[] = array('value'=>$result[$addressAttribute->getId()],'label'=>$addressLabel); 
    } 

    return $result; 
}