注文グリッド上の製品名と注文の往復方法
-
16-10-2019 - |
質問
販売注文グリッドに製品名、製品SKU、および注文出荷方法を追加しようとしています。
これが私の機能の外観です:
protected function _prepareCollection()
{
echo $collection = Mage::getResourceModel($this->_getCollectionClass())
->join(
'sales/order_item',
'`sales/order_item`.order_id=`main_table`.entity_id',
array(
'skus' => new Zend_Db_Expr('group_concat(`sales/order_item`.sku SEPARATOR ",")'),
'names' => new Zend_Db_Expr('group_concat(`sales/order_item`.name SEPARATOR ",")'),
)
)
->join(
'sales/order',
'`sales/order`.entity_id=`main_table`.entity_id',
array(
'shipping_description' => 'shipping_description'
)
);
echo $collection->getSelect();
$collection->getSelect()->group('entity_id');
$this->setCollection($collection);
return parent::_prepareCollection();
}
しかし、これはこのエラーを与えます:
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'entity_id' in-group statement is ambiguous
おそらく、2つのattitity_idsがあるためです main_table
.
これを修正する方法はありますか?
解決
$collection->getSelect()->group('entity_id');
entity_idは、多くのテーブルのPK名です。テーブル名も指定する必要があります。
$collection->getSelect()->group('maint_table.entity_id');
また、参照してください: $collection->getSelect()
クエリをmysqlにコピーして、根本的な問題をより理解することができます。
所属していません magento.stackexchange