在magento自定义模块网格页脚中添加总计

时间:2014-02-18 12:15:03

标签: magento grid magento-1.7

我在自定义模块中添加了销售订单网格。并且还在网格中获得页脚总行数。但问题是,当我在总计中添加“成人”列时,它不显示任何内容。adult,child,total我使用渲染器从订单中获取行数据。如何在页脚中获取adult,child,total的总数。 / p>

我使用下面的代码在grid.php中显示页脚总计

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

enter image description here

由于

1 个答案:

答案 0 :(得分:0)

将此功能添加到grid.php

public function getReport($from, $to) {
        if ($from == '') {
            $from = $this->getFilter('report_from');
        }
        if ($to == '') {
            $to = $this->getFilter('report_to');
        }
        $totalObj = Mage::getModel('reports/totals');
        $totals = $totalObj->countTotals($this, $from, $to);
        $this->setTotals($totals);
        $this->addGrandTotals($totals);
        return $this->getCollection()->getReport($from, $to);
    }

以及添加列添加'total' => 'sum'如下(我认为你做了这个,但一旦验证它正确):

$this->addColumn('item_id', array(
            'header' => Mage::helper('mymodule')->__('Item ID'),
            'align' => 'right',
            'index' => 'item_id',
            'type'  => 'number',
            'total' => 'sum',
        ));