我试图在管理配置中加载多选择字段中的客户属性。我确实得到了属性,但只得到了每个属性的首字母,而不是全文。这是我的代码,
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>
对此有什么想法吗?
当toOptionArray()返回以下格式的数组时,源模型通常是有用的:
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>
也许如果你把你的函数改成下面的,你会看到你想要的:
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;
}