如何在magento自定义网格中添加“总计”行

时间:2014-01-31 09:50:06

标签: magento grid

我正在创建一个新模块,在magento admin中使用特定产品的订单网格(这不是报表网格)我成功创建了新的订单网格,但我想在最后得到产品的总价,比如销售>报告。

请参阅图片

enter image description here

任何帮助将不胜感激,谢谢

1 个答案:

答案 0 :(得分:0)

实际上,由于@mageUz

,我正在回答我自己的问题

来源https://magento.stackexchange.com/questions/14190/how-to-add-a-total-row-in-a-magento-grid

在gird类中添加这些字段

class SSD_Uzkart_Block_Adminhtml_Uzkart_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
    protected $_countTotals = true;

    public function getTotals()
    {
        $totals = new Varien_Object();
        $fields = array(
            'uzkart_trans_amount' => 0, //actual column index, see _prepareColumns()
            'some_summarable_field' => 0,
            'another_countable_field' => 0,
        );
        foreach ($this->getCollection() as $item) {
            foreach($fields as $field=>$value){
                $fields[$field]+=$item->getData($field);
            }
        }
        //First column in the grid
        $fields['entity_id']='Totals';
        $totals->setData($fields);
        return $totals;
    }

    protected function _prepareColumns()
    {
        /**
         * another columns
         */

        $this->addColumn('uzkart_trans_amount', array(
            'header' => Mage::helper('uzkart')->__('Payment Amount'),
            'index' => 'uzkart_trans_amount',
            'type' => 'currency',
        ));

        /**
         * another columns
         */
    }

    /**
     * another methods
     */

}

<强> O / P

Result

您也可以使用其他方法请按照说明

您应该创建报告网格。请参阅Mage_Adminhtml_Block_Report_Customer_Orders_Grid报告网格并尝试阻止自己。

以下是有关自定义报告的精彩内容:

http://codegento.com/2011/03/creating-custom-magento-reports

http://www.summasolutions.net/blogposts/custom-reports-magento