我Mage_Adminhtml_Block_Sales_Order_Grid
使用自定义模块扩展了该类,以将多个客户属性(Magento EE 1.10)添加到网格中。
我在方法中使用三个连接将自定义属性添加到我的MyCompany_MyModule_Block_Adminhtml_Order_Grid
类中的集合中,如下所示:_prepareCollection()
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
//get the table names for the customer attributes we'll need
$customerEntityVarchar = Mage::getSingleton('core/resource')
->getTableName('customer_entity_varchar');
$customerEntityInt = Mage::getSingleton('core/resource')
->getTableName('customer_entity_int');
// add left joins to display the necessary customer attribute values
$collection->getSelect()->joinLeft(array(
'customer_entity_int_table'=>$customerEntityInt),
'`main_table`.`customer_id`=`customer_entity_int_table`.`entity_id`
AND `customer_entity_int_table`.`attribute_id`=148',
array('bureau'=>'value'));
$collection->getSelect()->joinLeft(array(
'customer_entity_varchar_table'=>$customerEntityVarchar),
'`main_table`.`customer_id`=`customer_entity_varchar_table`.`entity_id`
AND `customer_entity_varchar_table`.`attribute_id`=149',
array('index_code'=>'value'));
$collection->getSelect()->joinLeft(array(
'customer_entity_varchar_2_table'=>$customerEntityVarchar),
'`main_table`.`customer_id`=`customer_entity_varchar_2_table`.`entity_id`
AND `customer_entity_varchar_2_table`.`attribute_id`=150',
array('did_number'=>'value'));
$this->setCollection($collection);
return parent::_prepareCollection();
}
更新:虽然查看订单时一切正常,但当我尝试通过任何文本连接字段(index_code
或did_number
)搜索/过滤订单时,情况并不好。结果是 SQL 错误:“ SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'store_id' in where clause is ambiguous
.”
如果我删除除一个语句之外的所有leftJoin()
语句,也会存在此问题,因此表的两个(任何一个)连接都出现问题customer_entity_varchar
。