1

I want to override magento function model which located at app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php Mage_Sales_Model_Order_Pdf_Abstract, how to override the insertOrder function at this model from custom module?

1

Magento does not allow you to rewrite abstract classes.

The simplest solution would be copying the file to app/code/local/Mage/Sales/Model/Order/Pdf/Abstract.php and then editing the function as needed.

The only other solution would be rewriting all the classes that extend the abstract class within your own custom module. To do so, you would need rewrite all 4 classes that extend it as follows.

app/etc/modules/Custom_Module.xml

<?xml version="1.0"?>

<config>
    <modules>
        <Custom_Module>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Sales />
            </depends>
        </Custom_Module>
    </modules>
</config>

app/code/local/Custom/Module/etc/config.xml

<?xml version="1.0"?>

<config>
    <modules>
        <Custom_Module>
            <version>1.0.0</version>
        </Custom_Module>
    </modules>

    <global>
        <models>
            <custom_module>
                <class>Custom_Module_Model</class>
            </custom_module>

            <sales>
                <rewrite>
                    <order_pdf_creditmemo>Custom_Module_Model_Order_Pdf_Creditmemo</order_pdf_creditmemo>
                    <order_pdf_invoice>Custom_Module_Model_Order_Pdf_Invoice</order_pdf_invoice>
                    <order_pdf_shipment>Custom_Module_Model_Order_Pdf_Shipment</order_pdf_shipment>
                    <order_pdf_shipment_packaging>Custom_Module_Model_Order_Pdf_Shipment_Packaging</order_pdf_shipment_packaging>
                </rewrite>
            </sales>
        </models>
    </global>
</config>

app/code/local/Custom/Module/Model/Order/Pdf/Creditmemo.php

<?php
class Custom_Module_Model_Order_Pdf_Creditmemo extends Mage_Sales_Model_Order_Pdf_Creditmemo {
    protected function insertOrder(&$page, $obj, $putOrderId = true) {
        parent::insertOrder($page, $obj, $putOrderId = true);

        /* Add your custom code here */
    }
}

app/code/local/Custom/Module/Model/Order/Pdf/Invoice.php

<?php
class Custom_Module_Model_Order_Pdf_Invoice extends Mage_Sales_Model_Order_Pdf_Invoice {
    protected function insertOrder(&$page, $obj, $putOrderId = true) {
        parent::insertOrder($page, $obj, $putOrderId = true);

        /* Add your custom code here */
    }
}

app/code/local/Custom/Module/Model/Order/Pdf/Shipment.php

<?php
class Custom_Module_Model_Order_Pdf_Shipment extends Mage_Sales_Model_Order_Pdf_Shipment {
    protected function insertOrder(&$page, $obj, $putOrderId = true) {
        parent::insertOrder($page, $obj, $putOrderId = true);

        /* Add your custom code here */
    }
}

app/code/local/Custom/Module/Model/Order/Pdf/Shipment/Packaging.php

<?php
class Custom_Module_Model_Order_Pdf_Shipment_Packaging extends Mage_Sales_Model_Order_Pdf_Shipment_Packaging {
    protected function insertOrder(&$page, $obj, $putOrderId = true) {
        parent::insertOrder($page, $obj, $putOrderId = true);

        /* Add your custom code here */
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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