Magento 管理员自定义销售报告
我必须开发一个模块来导出产品、订单、客户组合属性的集合。因此,我认为与其为此目的修改核心销售报告,不如执行自定义功能。这些是我所做的步骤,但我无法生成它。为此使用了magento 1.4.1版本。
下 /var/www/magento141/app/code/core/Mage/Reports/etc/adminhtml.xml 为菜单添加了这些行。
<ereaders translate="title" module="reports">
<title>Sales Report</title>
<children>
<ereaders translate="title" module="reports">
<title>Sales Report</title>
<action>adminhtml/report_sales/ereaders</action>
</ereaders>
</children>
</ereaders>
下
/var/www/magento141/app/design/adminhtml/default/default/layout/sales.xml 添加了这些行作为过滤条件。
<adminhtml_report_sales_ereaders>
<update handle="report_sales"/>
<reference name="content">
<block type="adminhtml/report_sales_sales" template="report/grid/container.phtml" name="sales.report.grid.container">
<block type="adminhtml/store_switcher" template="report/store/switcher/enhanced.phtml" name="store.switcher">
<action method="setStoreVarName"><var_name>store_ids</var_name></action>
</block>
<block type="sales/adminhtml_report_filter_form_order" name="grid.filter.form">
----
</block>
</block>
</reference>
</adminhtml_report_sales_ereaders>
然后从 sales 复制所需的块、模型文件并将其全部重命名为 /var/www/magento141/app/code/core/Mage/Adminhtml/ 下的电子阅读器。
然后将电子阅读器的操作放在 /var/www/magento141/app/code/core/Mage/Adminhtml/controllers/Report/SalesController.php 下
public function ereadersAction()
{
$this->_title($this->__('Reports'))->_title($this->__('Sales'))->_title($this->__('EReaders Sales'));
$this->_showLastExecutionTime(Mage_Reports_Model_Flag::REPORT_ORDER_FLAG_CODE, 'ereaders');
$this->_initAction()
->_setActiveMenu('report/sales/ereaders')
->_addBreadcrumb(Mage::helper('adminhtml')->__('EReaders Sales Report'), Mage::helper('adminhtml')->__('EReaders Sales Report'));
$gridBlock = $this->getLayout()->getBlock('report_sales_ereaders.grid');
$filterFormBlock = $this->getLayout()->getBlock('grid.filter.form');
$this->_initReportAction(array(
$gridBlock,
$filterFormBlock
));
$this->renderLayout();
}
,当我使用 var_dump ==> 时//var_dump($this->getLayout()->getBlock('report_sales_ereaders.grid'));我只得到 bool(false) 。它不会调用电子阅读器网格,而是仅从 Sales 加载块和网格。
我搜索了大部分与报告相关的文件,但仍然无法找出问题所在。 希望你们中的许多人都经历过此类问题,请任何人告诉我哪里犯了错误或遗漏了什么。
I have to develop a module to export collection of product,order,customer combined attributes. So i thought rather than modifying the core sales report for this purpose better to do a custom functionality. These are the steps that i did but i am not able to produce it. Used magento 1.4.1 version for this.
Under
/var/www/magento141/app/code/core/Mage/Reports/etc/adminhtml.xml
Added these lines for menus.
<ereaders translate="title" module="reports">
<title>Sales Report</title>
<children>
<ereaders translate="title" module="reports">
<title>Sales Report</title>
<action>adminhtml/report_sales/ereaders</action>
</ereaders>
</children>
</ereaders>
Under
/var/www/magento141/app/design/adminhtml/default/default/layout/sales.xml
Added these lines for filter condition.
<adminhtml_report_sales_ereaders>
<update handle="report_sales"/>
<reference name="content">
<block type="adminhtml/report_sales_sales" template="report/grid/container.phtml" name="sales.report.grid.container">
<block type="adminhtml/store_switcher" template="report/store/switcher/enhanced.phtml" name="store.switcher">
<action method="setStoreVarName"><var_name>store_ids</var_name></action>
</block>
<block type="sales/adminhtml_report_filter_form_order" name="grid.filter.form">
----
</block>
</block>
</reference>
</adminhtml_report_sales_ereaders>
And then copied the needed block,model files from sales and renamed all of them into ereaders under /var/www/magento141/app/code/core/Mage/Adminhtml/.
Then placed action for ereaders under /var/www/magento141/app/code/core/Mage/Adminhtml/controllers/Report/SalesController.php
public function ereadersAction()
{
$this->_title($this->__('Reports'))->_title($this->__('Sales'))->_title($this->__('EReaders Sales'));
$this->_showLastExecutionTime(Mage_Reports_Model_Flag::REPORT_ORDER_FLAG_CODE, 'ereaders');
$this->_initAction()
->_setActiveMenu('report/sales/ereaders')
->_addBreadcrumb(Mage::helper('adminhtml')->__('EReaders Sales Report'), Mage::helper('adminhtml')->__('EReaders Sales Report'));
$gridBlock = $this->getLayout()->getBlock('report_sales_ereaders.grid');
$filterFormBlock = $this->getLayout()->getBlock('grid.filter.form');
$this->_initReportAction(array(
$gridBlock,
$filterFormBlock
));
$this->renderLayout();
}
Here when i use var_dump ==> //var_dump($this->getLayout()->getBlock('report_sales_ereaders.grid')); am getting bool(false) only. It does not call the ereaders grid, instead of its still loading blocks and grids from Sales only.
I searched most of the files related to report, am not still able to find out the problem.
Hope many of you gone through these sort of issues, please can anyone tell me where am making mistake or missing something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在布局文件中没有看到名为“report_sales_ereaders.grid”的块,如果您要使用该名称,则应该在布局中将“sales.report.grid.container”更改为“report_sales_ereaders.grid”。 getBlock 方法使用布局文件中的 name 属性来加载块。
如果您仍然遇到问题,请详细了解您在后台复制的块和模型。希望这有帮助。
I don't see a block named "report_sales_ereaders.grid" in your layout file, if that's the name you want to use, you should change "sales.report.grid.container" to "report_sales_ereaders.grid" in your layout. the getBlock method uses the name attribute in the layout file to load blocks from.
If you still have problems go into more detail about the blocks and models you copied in the background. hope this helps.
您没有名为 'report_sales_ereaders.grid' 的块,因为该块是由 Magento 动态创建的:
$this->_controller 是此处的关键。
然后您在块中定义它,看到您的 sales.xml 是“adminhtml/report_sales_sales”。
该块应该从 Mage_Adminhtml_Block_Widget_Grid_Container 扩展,并且您应该在该块的构造函数内定义 ::_controller:
另请注意上面的第一个代码 (_prepareLayout),Mage_Adminhtml_Block_Widget_Grid_Container 将尝试使用名为 (uri) 的块:
'something/report_sales_ereaders_grid',
因此您也需要该类,因此您可能希望使用
该块将具有名称(在您的布局内):“report_sales_ereaders.grid”
因此,根据您想要执行的操作,您在这里有两个选项:
1)更改 sales.xml 布局中块的类型,以便它指向您自己的块(您可以在那里定义我上面显示的“_controller”,等等)。
2) 更改
为,
因为“report_sales_sales”是块“adminhtml/report_sales_sales”(
Mage_Adminhtml_Block_Report_Sales_Sales
)内“_controller”的值。You don't have the block named 'report_sales_ereaders.grid' because that block is created dynamically by Magento here:
$this->_controller is the key here.
And you define it inside your block, which, seeing your sales.xml is "adminhtml/report_sales_sales".
That Block should extends from Mage_Adminhtml_Block_Widget_Grid_Container, and you should define ::_controller inside the contrusctor of that block:
Also note from the first code above (_prepareLayout) that Mage_Adminhtml_Block_Widget_Grid_Container will try to use a Block called (uri):
'something/report_sales_ereaders_grid'
so you need that class too, and therefore you probably want to change "something" with the node used in yout config.xml under
<blocks>
that block will have the name (inside your layout): "report_sales_ereaders.grid"
So, depending what you want to do, you have two options here:
1) Change the type of your block in your sales.xml layout, so it points to your own block (and you define there your "_controller" how I showed above, etc).
2) Change
to
because "report_sales_sales" is the value of "_controller" inside the block "adminhtml/report_sales_sales" (
Mage_Adminhtml_Block_Report_Sales_Sales
).