我的 Grid.php 文件中有以下代码:
function _prepareCollection () {
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()->joinLeft(
array('sfog' => 'sales_flat_order_grid'),
'main_table.entity_id = sfog.entity_id',
array('sfog.shipping_name','sfog.billing_name')
);
$collection->getSelect()->joinLeft(
array('sfo'=>'sales_flat_order'),
'sfo.entity_id=main_table.entity_id',
array(
'sfo.customer_email',
'sfo.weight',
'sfo.discount_description',
'sfo.increment_id',
'sfo.store_id',
'sfo.created_at',
'sfo.status',
'sfo.base_grand_total',
'sfo.grand_total'
)
);
我也想添加表 sales_order_item,但如果我添加此表,我会收到此错误:
具有相同 ID“119”的项目 (Mage_Sales_Model_Order) 已经存在
有什么办法吗?
最佳答案
假设您要加入 soi
,意思是 sales_order_item
,按 soi.item_id
分组
$collection->getSelect()->group('soi.item_id');
关于php - Magento 加入不同的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10834994/