The import products profile allows you to filter which products to export by name, sku…
I want to have the same functionality in the manage products page.
The admin will filter products in the grid and then click a “export” button to get the filtered products.
How can I add the “export” button? what template/block do I need to override?
When the admin click the button, how can I get the filtered collection?
How can I export the filtered collection to a csv file? Can I use the dataflow for that?
Thanks
You will need to implement a new massAction in the admin product controller. A good way to start is to have a look at the product controller and see how the other massActions are implemented.
Let’s have a look… First you will need to add a declaration of a massAction to a grid. This can be done in app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php. You need to add the following in the _prepareMassaction method:
Now you will have to implement this new action in the product controller (app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php):
The code is mostly copied from the massDeleteAction, but instead of deleting products you should add to the $content variable. After you are done creating the content of your csv export (you will probably need to add other fields to it) you need to call the _prepareDownloadResponse method of the controller class. That’s it, you have your custom export in place!
On a final note, once you are happy with the changes remember to move them to your local code pool so that your magento installation remains update-proof 🙂