【问题标题】:UPDATED: Magento add customer attribute filter to order grid更新:Magento 将客户属性过滤器添加到订单网格
【发布时间】:2011-06-21 17:46:22
【问题描述】:

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

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

第三个属性是一个选择,所以值存在于customer_entity_inteav_attribute_optioneav_attribute_option_value 表中。我向集合中添加了必要的值(使用$collection->getSelect()->joinLeft(.....)。同样,到目前为止一切都很好。

我的问题是能够同时显示过滤属性。

在我的MyCompany_MyModule_Block_Adminhtml_Order_Grid 类的_prepareColumns() 函数中,如果我添加这样的列, - 正如预期的那样 - 我可以在每一行上显示属性的值,但我没有得到下拉过滤器在标题中:

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"

【问题讨论】:

  • 当列类型为文本时,显示的值是存储在数据库中的整数还是从选项解析的文本?
  • @clockworkgeek 它们是从属性选项解析的文本 - 是问题吗?我的联接是否应该拉取整数值?
  • 我怀疑它应该在使用 options 类型时检索整数值,但不确定。如果你已经知道怎么做,那就试试吧!
  • @clockworkgeek 太棒了——成功了——回想起来是如此明显。既然你在滚动,你知道为什么store_id 在多网站设置中对于没有所有网站权限的管理员用户来说是模棱两可的(在 MySQL 查询中)吗?
  • 我最好的猜测是与这些额外表的连接方式有关。我认为,如果您要提供更多详细信息,就可以提出自己的问题,这已经足够复杂了。

标签: mysql custom-attributes magento mysql-error-1052


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-28
    • 1970-01-01
    • 2014-12-03
    • 1970-01-01
    • 1970-01-01
    • 2013-08-07
    • 1970-01-01
    相关资源
    最近更新 更多