カスタム モジュールを使用してクラスを拡張し、Mage_Adminhtml_Block_Sales_Order_Grid
いくつかの顧客属性 (Magento EE 1.10) をグリッドに追加しました。
次のような 3 つの結合を使用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
."
この問題は、ステートメントの 1 つを除くすべてを削除した場合にも存在するleftJoin()
ため、テーブルとの結合の両方 (いずれか) で問題が発生していcustomer_entity_varchar
ます。