多选字段未正确加载值 - 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>
对此有什么想法吗?
I am trying to load customer attributes in multi-select field in admin configuration.
I do get the attributes but only get the initials of each one of them and not the full text. This is my code,
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;
}
And this is my system.xml code
<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>
Any ideas on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当 toOptionArray() 返回以下格式的数组时,源模型通常很有用:
上面的内容将呈现如下:
也许如果将函数更改为以下内容,您将看到您想要的内容:
Source models are generally useful when toOptionArray() returns an array of the following format:
The above would be rendered as follows:
Perhaps if you change your function to the following, you'll see what you want: