Magento 1.9 – Override Method of Abstract File in Invoice PDF

magento-1.9override-model

I want to override a method insert Totals of this file :- app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php

How can I do that? Can anyone please guide?

I saw this post : Changing PDF appearance which is quite good but still can't understand which file to make, where to make etc… We have our custom module in which we can do the stuff but I can not understand which file to make & where to put to override abstract class method.

Can anyone please guide step by step implementation of this?

Here is the further update :-
What I tried is : in my config.xml file I put this :-

<sales>
<rewrite><order_pdf_invoice>Promotion_Multidiscount_Model_Sales_Order_Pdf_Invoice</order_pdf_invoice>
</rewrite>
</sales>

And I copied code/core/Mage/Sales/Model/Order/Pdf/Invoice.php in my module's folder that is code/local/Promotion/Multidiscount/Model/Sales/Order/Pdf/Invoice.php & I modified that particular function only & kept rest of the functions as it is but now this error coming when I go to Invoice of any order & click Print button.

Error :-

Fatal error: Uncaught Error: Call to a member function getPdf() on boolean in /opt/lampp/htdocs/magento_store/app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php:119 Stack trace: #0 /opt/lampp/htdocs/magento_store/app/code/core/Mage/Adminhtml/controllers/Sales/Order/InvoiceController.php(489): Mage_Adminhtml_Controller_Sales_Invoice->printAction() #1 /opt/lampp/htdocs/magento_store/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Adminhtml_Sales_Order_InvoiceController->printAction() #2 /opt/lampp/htdocs/magento_store/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('print') #3 /opt/lampp/htdocs/magento_store/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http)) #4 /opt/lampp/htdocs/magento_store/app/code/core/Mage/Core/Model/App.php(365): Mage_Core_Controller_Varien_Front->dispatch() #5 /opt/lampp/htdocs/magento_store/app/Mage.php(683): Mage in /opt/lampp/htdocs/magento_store/app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php on line 119

Url is like this :-
http://localhost/magento_store/index.php/admin/sales_order_invoice/print/invoice_id/43/key/be7b6b59159f5523398350f73d1236c2/

Thank you.

Best Answer

All the things were correct except one - Folder structure. I did a mistake by placing an overriding file in sales folder in model folder of my module.

I wanted to override a method insertTotals inside the following file app\code\core\Mage\Sales\Model\Order\Pdf\Abstract.php

So in my module's config file I did a change :-

<sales>
<rewrite><order_pdf_invoice>Promotion_Multidiscount_Model_Sales_Order_Pdf_Invoice</order_pdf_invoice>
</rewrite>
</sales>

But in my module, I put Invoice.php file here app\code\local\Promotion\Multidiscount\Model\Sales\Order\Pdf\Invoice.php

Actually it should be here

app\code\local\Promotion\Multidiscount\Model\Order\Pdf\Invoice.php
Related Topic