0

Mage_Adminhtml_Block_Sales_Order_Grid使用自定义模块扩展了该类,以将多个客户属性(Magento EE 1.10)添加到网格中。

我添加的两个属性是文本字段(即它们存在于customer_entity_varchar表格中,我能够将它们添加到集合中并在网格中显示它们。到目前为止一切都很好。

第三个属性是一个选择,因此值存在于customer_entity_inteav_attribute_optioneav_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"

4

1 回答 1

0

@clockworkgeek 回答了我问题的第一部分。

问题是我joinLeft()正在从属性选项中检索文本值,而我应该在使用'type => 'options'.

一旦我将我的更改joinLeft()为仅从customer_entity_int(实际上是一个更简单的连接)中检索整数值,过滤和显示就会完美无缺 - 谢谢先生。

我将把我的第二个问题(关于权限引起的 SQL 错误)作为一个单独的问题重新发布。

于 2011-06-27T22:33:07.550 回答