Tim Sajt
Tim Sajt

Reputation: 117

Magento - Add Mass Actions for Print PDF Invoice

I have question, how can I add a mass action to print invoice in PDF. I need two different PDF invoice (one is default "Print Invoice"), so I want to add additional action "Print invoice 2". How can I do that to start printing "Print invoice 2"?

Hope someone can help!

Upvotes: 2

Views: 2564

Answers (1)

Jim OHalloran
Jim OHalloran

Reputation: 5908

Assuming you want to add the mass actions to the invoices grid (Sales > Invoices in the admin), you will need to do the following:

Rewrite the Mage_Adminhtml_Block_Sales_Invoice_Grid class and replace it with your own. Your new class should be in it's own extension and inherit from Mage_Adminhtml_Block_Sales_Invoice_Grid. If you're not sure how to rewrite a block, this blog post should help you out. Note: You could just copy the grid block to app/code/local/ but that makes upgrading Magento difficult. A better approach is a rewrite and override the minimum possible amount of functionality.

Your class should provide it's own _prepareMassaction function which then adds the new action. The following code (while completely untested) should do it:

class MyNamspace_Extension_Block_Adminhtml_Invoice_Grid extends Mage_Adminhtml_Block_Sales_Invoice_Grid {
    protected function _prepareMassaction() {
        parent::_prepareMassaction();

        $this->getMassactionBlock()->addItem('pdfinvoices_order2', array(
             'label'=> Mage::helper('myextension')->__('PDF Invoices2'),
             'url'  => $this->getUrl('myroute/mycontroller/myaction'),
        ));

        return $this;
    }
}

The "url" param on the addItem() call should point to your own controller where you can implement your own logic for generation of PDFs. The standard mass action PDF generator can be found in app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php at line 129 if you'd like some inspiration.

Upvotes: 3

Related Questions