Here I am giving my first steps in magento.
And I came across a nescessidade
in: Reports-> Products-> Products ordered
Has the following filters:
Would add a new filter, such as that in: Reports-> Sales-> Orders
Is that possible? If yes, could someone give me some help? I did a search for extension or someone with similar problems but not getting suceso, I'll be grateful for any guidance.
Thank you for your attention.
Considering that you said these are your first steps in Magento this might be tricky, bit I try to answer it.
You'll need to know how to create your own module. I suggest following a tutorial, there are lot's of them out there. For example: http://www.smashingmagazine.com/2012/03/01/basics-creating-magento-module/
Then you can start changing the products ordered report in your extension. I've just done this, so it might not be optimal or 100% bug-free, but it should give you an idea. Please look for
yournamespace
andyourmodule
(case-sensitive) in below code and replace it with your namespace and module name.First, in
app/design/adminhtml/default/default/layout/yourmodule.xml
we define the blocks needed for the filter and report grid:And we define the new block in
app/code/local/Yournamespace/Yourmodule/Block/Adminhtml/Report/Product/Sold.php
:Then, we need a custom controller for the product sold action, overriding the default one. In
app/code/local/Yournamespace/Yourmodule/controllers/Adminhtml/Report/ProductController.php
:Then in
app/code/local/Yournamespace/Yourmodule/Block/Adminhtml/Report/Filter/Form.php
add your custom filter field: (I added category filter as an example.)Then I create the grid in
app/code/local/Yournamespace/Yourmodule/Block/Adminhtml/Report/Product/Sold/Grid.php
: (Explanation below...)Things to note here:
$this->setDateFilterVisibility(false)
removes the default filter.$collection->initReport('yournamespace_yourmodule/report_product_sold_collection');
initializes the grid with our collection (will be defined further down).$collection->setCategoryFilter($this->getFilter('product_categories'));
will set the filter on our collection. This needs to be defined as this is not a default filter, unlike thefrom
andto
filters._prepareColumns()
I add the product category column to the grid.Then we need the following classes to pass our custom filter value from the grid to the report collection, then to the report and eventually to the products sold collection:
In
app/code/local/Yournamespace/Yourmodule/Model/Mysql4/Report/Collection.php
:In
app/code/local/Yournamespace/Yourmodule/Model/Report.php
:In
app/code/local/Yournamespace/Yourmodule/Model/Mysql4/Report/Product/Sold/Collection.php
:I ripped off some code from above. Replace it with your own.
$this->getSelect()
will give you the select. (Open theVarien_Db_Select
class if you need more info on this.)Finally, to get this all working (hopefully) we have to have our rewrites (overrides) defined in
app/code/local/Yournamespace/Yourmodule/etc/config.xml
: (You should have this file already when you created your module, I just post the new parts. All these should go between<config>
and</config>
.)To make use of our controller:
For the report and report collection overrides:
And for the new blocks:
Hope this will work for you.