Magento 1.9.x自定义报告:按日期范围从另一个表添加SUM

时间:2019-03-20 09:01:18

标签: mysql magento magento-1.9

我想根据https://www.atwix.com/magento/simple-products-report/上的教程在Magento 1.9中创建自定义报告

在此报告中,我将需要另外一列,在报告的时间间隔中,另一表中的SUMproduct qty

该报告与报告->产品->产品订购者类似。

我可以选择日期(fromto),但是这些日期在Frontline_Simpleproductsreport_Block_Report_Product_Inventory中不可用。

问:如何在“渲染”功能中获取日期(fromto)?

还:还有另一种方法可以根据报告日期范围来计算总和吗?

以下是我当前实施中的相关部分。

/app/code/local/Frontline/Simpleproductsreport/Block/Report/Product/Simplesold/Grid.php

<?php

class Frontline_Simpleproductsreport_Block_Report_Product_Simplesold_Grid extends Mage_Adminhtml_Block_Report_Product_Sold_Grid
{
    /**
     * Setting up proper product collection name for a report
     *
     * @return Frontline_Simpleproductsreport_Block_Report_Product_Simplesold_Grid
     */
    protected function _prepareCollection()
    {
        Mage_Adminhtml_Block_Report_Grid::_prepareCollection();

        $this->getCollection()
            ->initReport('frontline_simpleproductsreport/simpleproduct_sold_collection');

        return $this;
    }

    protected function _prepareColumns()
    {

        $this->addColumn('entity_id', array(
            'header'    => Mage::helper('reports')->__('ID'),
            'index'     => 'entity_id',
            'align'     => 'left'
        ));

        $this->addColumn('name', array(
            'header'    => Mage::helper('reports')->__('Product Name'),
            'index'     => 'name',
            'align'     => 'left'
        ));

        $this->addColumn('ordered_qty', array(
            'header'    => Mage::helper('reports')->__('Quantity Ordered'),
            'index'     => 'ordered_qty',
            'align'     => 'left'
        ));

        $this->addColumn('inventory', array(
            'header'    => Mage::helper('reports')->__('Inventory'),
            'index'     => 'inventory',
            'align'     => 'left',
            'renderer'  => 'Frontline_Simpleproductsreport_Block_Report_Product_Inventory',
        ));

        return parent::_prepareColumns();
    }
}

/app/code/local/Frontline/Simpleproductsreport/Block/Report/Product/Inventory.php

<?php

class Frontline_Simpleproductsreport_Block_Report_Product_Inventory extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{

    public function render(Varien_Object $row)
    {
        $movements = Mage::getModel('stockmonitor/stockmovement')->getCollection()
           ->addFieldToFilter('product_id', $row->getData('entity_id'))
           ->addFieldToFilter('order_id', 0)
           ->getColumnValues('qty_change');

        return count($movements);
    }

}

预先感谢:)

0 个答案:

没有答案