我已使用自定义模块扩展Mage_Adminhtml_Block_Sales_Order_Grid
类,以将多个客户属性(Magento EE 1.10)添加到网格中。
我添加的两个属性是文本字段(即它们存在于customer_entity_varchar
表中,我能够将它们添加到集合中并在网格中显示它们。到目前为止一切都很好。
第三个属性是select,因此值存在于customer_entity_int
,eav_attribute_option
和eav_attribute_option_value
表中。我在集合中添加了必要的值(使用$collection->getSelect()->joinLeft(.....)
。再次,到目前为止一直很好。
我的问题是能够同时显示和过滤属性。
在_prepareColumns()
类的MyCompany_MyModule_Block_Adminhtml_Order_Grid
函数中,如果我添加这样的列, - 正如预期的那样 - 我可以在每一行显示属性的值,但是我没有得到标题中的下拉过滤器:
protected function _prepareColumns()
{
...
$this->addColumn('bureau', array(
'header' => Mage::helper('sales')->__('Bureau'),
'index' => 'bureau',
'type' => 'text'
));
...
}
按照status
的示例,并添加这样的列,给我标题中的下拉过滤器,但它不再显示每行中属性的值:
protected function _prepareColumns()
{
...
$this->addColumn('bureau', array(
'header' => Mage::helper('sales')->__('Bureau'),
'index' => 'bureau',
'type' => 'options',
'options' => $this->_getBureauOptions(),
'filter_index' => 'value_option_table.option_id'
));
...
}
protected function _getBureauOptions()
{
$bureau = Mage::getResourceModel('eav/entity_attribute_collection')
->setCodeFilter('bureau')
->getFirstItem();
$bureauOptions = $bureau->getSource()->getAllOptions(false);
$optionsArr = array();
foreach ($bureauOptions as $option) {
$optionsArr[$option['value']] = $option['label'];
}
return $optionsArr;
}
非常感谢任何建议/解释。
更新
事实证明,当管理员用户只拥有某些网站的权限时,我的代码也会在多网站环境中导致SQL错误:
"SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'store_id' in where clause is ambiguous"
答案 0 :(得分:0)
@clockworkgeek得到了我问题第一部分的答案。
问题是我的joinLeft()
正在从属性选项中检索文本值,而我应该在使用'type => 'options'
时检索整数值。
一旦我将joinLeft()
更改为仅从customer_entity_int
检索整数值(实际上是一个更简单的连接),过滤和显示工作完美无瑕 - 谢谢先生。
我将重新发布我的第二个问题(关于权限导致的SQL错误)作为一个单独的问题。