加入Magento

时间:2013-06-20 15:39:41

标签: magento join

我是初学者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();

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

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

提前感谢您的所有想法和帮助。

1 个答案:

答案 0 :(得分:0)

我在搜索了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()
            );