1

We need some changes done in the PDF that magento gives. I've looked at many guides and have found some solutions that work but are not really how I want it to be done. Many guides tell you to copy the files you want to edit, paste it in the local folder and make your changes there. But the changes are really small so I wanna know if there is a better way to make these small changes. The changes have to be done in these 2 files.

App/code/Mage/Core/Sales/Model/Order/Pdf/Abstract.php
App/code/Mage/Core/Sales/Model/Order/Pdf/Invoice.php

And all that we are going to change on these files are some colours. We could also override these classes but one of the classes is an abstract class. I am not sure if it's right to extend these and change them in local.

1 Answer 1

2

Inchoo published an article about rewriting code classes. It will minimalize the impact of your changes

Config.xml

<config>
    <global>
        <models>
            <sales>
                <rewrite>
                   <order_pdf_invoice>[Namespace]_[Module]_Model_Sales_Order_Pdf_Invoice</order_pdf_invoice>
                </rewrite>
            </sales>
        </models>
    </global>
</config>

Link to the article: http://inchoo.net/magento/overriding-magento-blocks-models-helpers-and-controllers/

important

You can't rewrite an abstract class, you will need to rewrite the classes that use the abstract class copying the method you want to rewrite to the new class and add your changes there

2
  • Would I also have to follow these steps if I want to override methods? All I am doing here is changing some simple colours in the methods in that class. (mainly talking about the abstract class). What is the best practice here?
    – Jordy
    Mar 17, 2015 at 18:25
  • Jup, specially for overwriting methods. Its the only way to do it Mar 17, 2015 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.