Php 如何使用自定义模块在下拉列表中显示客户属性

Php 如何使用自定义模块在下拉列表中显示客户属性,php,magento,Php,Magento,我在admin中创建了一个自定义选项卡,需要管理客户属性 我想加载该部分中的所有客户属性,并对每个属性保留一个复选框 这样,当选中或取消选中复选框时,将根据所选内容在“管理客户”网格中显示/隐藏列 我想知道如何在该部分中显示所有客户属性,每个属性都有一个复选框?您可以使用该复选框返回一个属性数组 然后,我们需要在模块的system.xml中添加一个新字段 <fieldname translate="label"> <label>Customer

我在admin中创建了一个自定义选项卡,需要管理客户属性

我想加载该部分中的所有客户属性,并对每个属性保留一个复选框

这样,当选中或取消选中复选框时,将根据所选内容在“管理客户”网格中显示/隐藏列

我想知道如何在该部分中显示所有客户属性,每个属性都有一个复选框?

您可以使用该复选框返回一个属性数组

然后,我们需要在模块的system.xml中添加一个新字段

<fieldname translate="label">
    <label>Customer Attributes</label>
    <frontend_type>checkboxes</frontend_type>
    <source_model>yourmodule/source_customer_attribute</source_model>
    <show_in_default>1</show_in_default>
</fieldname>

客户属性
复选框
yourmodule/source\u customer\u属性
1.
这工作得出人意料地好,出人意料的是,这些类没有在核心中使用。除了
复选框
之外,该类型还可以是
收音机
,这同样有效。

找到了答案

这是最后的代码。显然,首先非常感谢您对代码的帮助

    $attributes = Mage::getModel('customer/entity_address_attribute_collection');
    $result = array();
    foreach ($attributes as $attribute)
    {
        if (($label = $attribute->getFrontendLabel()))
            $result[$attribute->getId()] = $label;
    }
    $attributes1 = Mage::getModel('customer/entity_attribute_collection');
    $result1 = array();
    foreach ($attributes1 as $attribute1)
    {
        if (($label1 = $attribute1->getFrontendLabel()))
            $result1[$attribute1->getId()] = $label1;
    }
    $final = array_merge($result, $result1);

    return $final; 

当我说客户属性时,我指的是属性标签,如姓名、电话、电子邮件等。我希望所有这些属性都在下拉列表中。就像我们可以为产品设置属性一样,我需要为客户设置属性。谢谢您的回复。我会试试你的代码,但就在那之前,我还会问你一件事。如何在我的管理部分的弹出窗口小部件窗体中显示此带有属性标签的复选框。现在,我已经在管理区域创建了一个选项卡,其中包含一个用于管理客户属性的部分。弹出式表单目前只有一个文本框。我希望这些复选框以这种形式显示,那么system.xml如何理解这些复选框应该在我的管理部分中输出?1)我得到许多没有标签的黑色复选框。如何摆脱这种情况?2)他们在我的管理区页面顶部得到了回应。我希望它们显示在我创建的新部分的弹出窗口小部件表单中。如何做到这一点?我还创建了另一个数组来检索具有相同代码的客户地址属性,只需将('customer/customer')替换为('customer/address'),但为什么会有这么多没有标签的空白复选框?请回复。多亏了你,我终于明白了一些道理。我不知道你打算使用配置部分。使用
Varien\u Data\u Form\u Element\u复选框可能会有一个巧妙的解决方法,但我以前从未尝试过这种方法。我现在就去试试。。。
<fieldname translate="label">
    <label>Customer Attributes</label>
    <frontend_type>checkboxes</frontend_type>
    <source_model>yourmodule/source_customer_attribute</source_model>
    <show_in_default>1</show_in_default>
</fieldname>
    $attributes = Mage::getModel('customer/entity_address_attribute_collection');
    $result = array();
    foreach ($attributes as $attribute)
    {
        if (($label = $attribute->getFrontendLabel()))
            $result[$attribute->getId()] = $label;
    }
    $attributes1 = Mage::getModel('customer/entity_attribute_collection');
    $result1 = array();
    foreach ($attributes1 as $attribute1)
    {
        if (($label1 = $attribute1->getFrontendLabel()))
            $result1[$attribute1->getId()] = $label1;
    }
    $final = array_merge($result, $result1);

    return $final;