我Mage_Adminhtml_Block_Sales_Order_Grid
使用自定义模块扩展了该类,以将多个客户属性(Magento EE 1.10)添加到网格中。
我添加的两个属性是文本字段(即它们存在于customer_entity_varchar
表格中,我能够将它们添加到集合中并在网格中显示它们。到目前为止一切都很好。
第三个属性是一个选择,因此值存在于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"