Hard Join in Magento



我是一个初学者Magento开发人员,我有一个困难的任务,在网格中添加一个特殊的列。

列命名为Type RMA。我做了sql查询,但我需要翻译它在Magento我的查询是:

 SELECT t1.*, (t3.total_qty_ordered - t2.qty_requested) as 'type_rma' 
FROM enterprise_rma_grid as t1 
JOIN enterprise_rma_item_entity as t2 
ON t1.entity_id = t2.entity_id 
JOIN sales_flat_order as t3 ON t1.order_id = t3.entity_id;

在我的_prepareCollection()中,我有这样的内容:

$collection = $this->getCollection();
        $collection->getSelect()
            ->join();

我不知道如何翻译我的SQL代码在一个magento。我的目标是将上面计算的值添加为名为"type_rma"的新列,并将其显示在我的网格中:

$this->addColumn('type_rma', array(
            'header'  => Mage::helper('enterprise_rma')->__('Type RMA'),
            'type'    => 'options',
            'width'   => '100px',
            'index'   => 'type_rma'
        ));

提前感谢你的建议和帮助。

经过10个小时的搜索,我找到了解决方案…

$collection->getSelect()
            ->join(
                array('t2' => 'enterprise_rma_item_entity'), 'main_table.entity_id = t2.entity_id',
                array('type_rma' => new Zend_Db_Expr("(t3.total_qty_ordered - t2.qty_requested)")
                )
            )->join(
                array('t3' => 'sales_flat_order'), 'main_table.order_id = t3.entity_id',
                array()
            );

最新更新