2

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!

Tim Sajt
  • 117
  • 5
  • 11

1 Answers1

3

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.

Jim OHalloran
  • 5,859
  • 2
  • 37
  • 57
  • I need two mass actions in the invoices grid (Sales > Invoices. One is as default "Print Invoices" and this is ok. So I need second one "Print Invoices 2". I already done modify files in app/code/local/Mage/Sales/Model/Order/Pdf for "Print Invoices" (this is ok) and app/code/local/Mage/Sales/Model/Order/Pdfn for "Print Invoices 2" I have problem, because I don't know, how and what I must to do, that "Print Invoices 2" will work with files in local/Mage/Sales/Model/Order/Pdfn Before I start modify Invoice I copy local/Mage/Sales/Model/Order/Pdf to local/Mage/Sales/Model/Order/Pdfn – Tim Sajt Oct 18 '12 at 19:41