Php 变更管理客户&x27;s网格
我已经创建了一个自定义模块,它在管理配置面板中显示一个选项卡和一个部分来管理客户属性 我已经加载了所有客户属性,每个属性都有一个复选框 这是我的代码,用于将所有客户属性显示为复选框。我希望从这里选择的复选框值作为列添加到Manage Customer网格中。 Model/Attributes.phpPhp 变更管理客户&x27;s网格,php,magento,Php,Magento,我已经创建了一个自定义模块,它在管理配置面板中显示一个选项卡和一个部分来管理客户属性 我已经加载了所有客户属性,每个属性都有一个复选框 这是我的代码,用于将所有客户属性显示为复选框。我希望从这里选择的复选框值作为列添加到Manage Customer网格中。 Model/Attributes.php $attributes = Mage::getModel('customer/entity_address_attribute_collection'); $result = array
$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;
现在,根据这些复选框的选择,我想在“管理客户”网格中添加一个额外的列
我尝试检索selected复选框的值,但只得到数组索引号
Mage::getStoreConfig('sectionname/groupname/fieldname');
有人能告诉我如何获取选中复选框的值,并根据该复选框表示的选择添加一列吗
提前感谢。我会在您的模块中,在config.xml中设置您正在使用自己的块(继承自
Mage\u Adminhtml\u Block\u Customer\u Grid
)对块Mage\u Adminhtml\u Block\u Customer\u Grid
进行过度编译,并在您自己的块中生成一个函数
protected function _prepareColumns()
{
$this->addColumn('mycolumn', array(
'header' => Mage::helper('customer')->__('My Column'),
'index' => 'key',
));
return parent::_prepareColumns();
}
在不了解更多数据的情况下,很难给出更好的建议,但这应该足以让您开始使用。当您使用时,您正在销毁正确的索引,这些索引应该是属性ID。另外,给变量起一个有意义的名字也是一种很好的做法
$result = array();
$addressAttributes = Mage::getModel('customer/entity_address_attribute_collection');
foreach ($addressAttributes as $addressAttribute)
{
if (($addrlabel = $addressAttribute->getFrontendLabel()))
$result[$addressAttribute->getId()] = $addrlabel;
}
$customerAttributes = Mage::getModel('customer/entity_attribute_collection');
foreach ($customerAttributes as $customerAttribute)
{
if (($custlabel = $customerAttribute->getFrontendLabel()))
$result[$customerAttribute->getId()] = $custlabel;
}
return $result;
我想下一步是删除网格父级将添加的列,这些列存储在网格的protected\u columns
属性中。并非所有列都要删除,例如massaction列。然后将您选择的列添加回
protected function _prepareColumns()
{
parent::_prepareColumns();
// remove the excess columns here
$attributeIds = Mage::getStoreConfig('sectionname/groupname/fieldname');
$attributes = Mage::getModel('eav/entity_attribute')->getCollection()
->addFieldToFilter('attribute_id', array('in' => $attributeIds));
foreach ($attributes as $attribute)
{
$options = array();
if ($attribute->getFrontendInput() == 'select') {
foreach ($attribute->getSource()->getAllOptions() as $value) {
$options[$value['value']] = $value['label'];
}
}
$this->addColumn($attribute->getCode(), array(
'index' => $attribute->getCode(),
'header' => $attribute->getFrontendLabel(),
'type' => $attribute->getFrontendInput(),
'options' => $options
));
}
return $this;
}
这种方法可能会丢失有用的格式,如列宽等。因此,更复杂的方法是确定哪些列已经就位并保留它们,然后只删除那些尚未选中的列。客户端还是服务器端?JQuery?更多信息…客户端或服务器端是什么意思?这在Magento后端的配置面板中。您正在尝试这样做吗?不完全一样。我的代码非常简单,只控制网格中列的添加和删除部分。我相信这是修改后的config.xml代码代码‘ConstantMedia_Adminhtml_Block_Customer_Grid’/code‘我刚刚编辑了我的问题,供那些想清楚了解我需要什么的人参考。谢谢你提供的有用信息。我会记住的。此外,我认为除了prepareCollection()之外,prepareCollection()也会有一些变化。你怎么看?我也不想删除任何现有的列。如果列不存在,我只想添加一个附加列。尝试您的代码确实添加了一次列,但当我再次尝试时,开始抛出错误。此外,它仅显示getSource()->getAllOptions()的“数组”,而不实际显示选项。和性别一样,它在下拉列表中显示了三次数组,而不是显示男性和女性。你认为你能在这里透露一些信息吗?谢谢您需要向集合中添加地址属性,如果您不检查所选的地址属性,则添加所有地址属性可能无关紧要,而且可能会稍微慢一点。当网格需要选项散列时,
getAllOptions
返回一个选项数组,因此我更新了我的答案,以便在它们之间进行转换,还包括可能导致错误的健全性检查。如果不通过查看日志了解更多有关错误的信息,我就无法说出它的真正含义。也许你可以自己解决;-)“向集合添加地址属性”是什么意思?在任何情况下,我的专栏都没有被添加?我觉得预收也必须更改。