2011-12-16 12 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>  

この上の任意のアイデアですか?

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

以下のようにレンダリングされます:

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

おそらく、あなたはあなたの関数を変更した場合toOptionArray()は、次の形式の配列を返すとき

答えて

0

ソースモデルは、一般的に便利です次は、あなたが望むものが表示されます:

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; 
} 
関連する問題