【发布时间】:2014-06-25 08:16:32
【问题描述】:
我正在尝试创建已成功创建的自定义报告,但我无法使用过滤器值,例如周期(日/月/年)。当它的日子显示完美的结果,但当它的月份和年份时,它会降低结果。
我的文件详情 块\Adminhtml\Commissionreport.php
<?php
class Magestore_Commissionreport_Block_Adminhtml_Commissionreport extends Mage_Adminhtml_Block_Widget_Grid_Container {
public function __construct()
{
$this->_controller = 'adminhtml_commissionreport';
$this->_blockGroup = 'commissionreport';
$this->_headerText = Mage::helper('commissionreport')->__('Commission Report');
parent::__construct();
$this->_removeButton('add');
}
}
Block\Adminhtml\Commissionreport\Grid.php
<?php
class Magestore_Commissionreport_Block_Adminhtml_Commissionreport_Grid extends Mage_Adminhtml_Block_Report_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('commissionreportGrid');
$this->setDefaultSort('created_at');
$this->setDefaultDir('ASC');
$this->setSaveParametersInSession(true);
}
protected function _prepareCollection()
{
parent::_prepareCollection();
// Get the data collection from the model
$this->getCollection()->initReport('commissionreport/commissionreport');
}
protected function _prepareColumns()
{
$this->addColumn('created_at', array(
'header' => Mage::helper('commissionreport')->__('Created At'),
'align' =>'left',
'sortable' => true,
'index' => 'created_at',
));
$this->addColumn('order_id', array(
'header' => Mage::helper('commissionreport')->__('Order Id'),
'align' =>'left',
'sortable' => true,
'index' => 'order_id',
));
$this->addColumn('fullname', array(
'header' => Mage::helper('commissionreport')->__('Customer Name'),
'align' =>'left',
'width' =>'550px',
'index' => 'fullname',
));
$this->addColumn('total_commission', array(
'header' => Mage::helper('commissionreport')->__('Commission Earned'),
'align' =>'left',
'total' =>'sum',
'width' =>'350px',
'index' => 'total_commission',
));
$this->addExportType('*/*/exportCsv', Mage::helper('commissionreport')->__('CSV'));
$this->addExportType('*/*/exportXml', Mage::helper('commissionreport')->__('XML'));
return parent::_prepareColumns();
}
public function getRowUrl($row)
{
return false;
}
}
Commissionreport\controllers\Adminhtml\CommissionreportController.php
<?php
class Magestore_Commissionreport_Adminhtml_CommissionreportController extends Mage_Adminhtml_Controller_Action
{
protected function _initAction() {
$this->loadLayout()
->_setActiveMenu('rewards/rewards')
->_addBreadcrumb(Mage::helper('adminhtml')->__('Rewards Transaction'), Mage::helper('adminhtml')->__('Rewards Transaction'));
return $this;
}
public function indexAction() {
$this->_initAction()
->renderLayout();
}
}
Commissionreport\Model\Commissionreport.php
<?php
class Magestore_Commissionreport_Model_Commissionreport extends Mage_Core_Model_Mysql4_Collection_Abstract
{
protected function _construct()
{
$this->_init('rewards/rewards');
}
protected function _joinFields($from = '', $to = '')
{
$firstnameAttr = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'firstname');
$lastnameAttr = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'lastname');
$this->getSelect()
->join( array('order_item'=> sales_flat_order_item), 'order_item.quote_item_id = main_table.item_id', array('order_item.created_at'))
->join( array('quote_item'=> sales_flat_quote_item), 'quote_item.item_id = main_table.item_id', array('quote_item.commission', 'quote_item.product_id', 'quote_item.qty'));
$this->addFieldToFilter('order_item.created_at' , array("from" => $from, "to" => $to, "datetime" => false));
return $this;
}
public function setDateRange($from, $to)
{
$this->_reset()
->_joinFields($from, $to);
return $this;
}
public function setStoreIds($storeIds)
{
return $this;
}
}
?>
当我选择月份时,它会显示所有记录的完美结果
但是当我们选择月份或年份时,它会减少结果
【问题讨论】:
-
这个问题似乎离题了,因为有关 Magento 的问题应该在专门的 Stack Exchange 站点上提出:Magento
标签: php magento report magento-1.8