0
votes

There is a sendEmail function inside the Invoice.php class at app\code\core\Mage\Sales\Model\Order\Invoice.php that I wanted to change hence I thought I should extend the class and make my changes in the local module.

I started off by making a directory on the server called

/public_html/app/code/local/Mymodule

Then I added the config.xml as follows:-

/public_html/app/code/local/Mymodule/Sales/etc which has the following config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Mymodule_Sales>
            <version>0.1</version>
        </Mymodule_Sales>
    </modules>
    <global>
       <models>
          <sales>
              <rewrite>
                  <order_invoice>Mymodule_Sales_Model_Order_Invoice</order_invoice>
              </rewrite>
          </sales>
       </models>
    </global>
</config>

I then created another folder as follows

/public_html/app/code/local/Mymodule/Sales/Model

which houses Invoice.php

<?php
class Mymodule_Sales_Model_Order_Invoice extends Mage_Sales_Model_Order_Invoice
{
    /**
     * Send email with invoice data
     *
     * @param boolean $notifyCustomer
     * @param string $comment
     * @return Mage_Sales_Model_Order_Invoice
     */
    public function sendEmail($notifyCustomer = true, $comment = '')
    {

I have disabled the original function in the original class and when I try to send an email it gives me an error.

What am I doing wrong?

1

1 Answers

0
votes

Please tell us specifically the error message you are getting, but at first glance you need to put the file Invoice.php into the folder /Order so the full path is this:

     /public_html/app/code/local/Mymodule/Sales/Model/Order/Invoice.php

For your case, where a module is also rewriting the this function (re comments below), you need to be careful about the order in which Magento loads the config.xml. Two modules cannot rewrite the same function but you can build an inheritance chain. So Oeditor_Ordereditor_Model_Order_Invoice can extend Mage_Sales_Model_Order_Invoice and then your Mymodule_Sales_Model_Order_Invoice can extend Oeditor_Ordereditor_Model_Order_Invoice. Then to make sure Magento loads these dependencies in the right order, the xml you need to put into your module config app/etc/modules/Mymodule_Sales.xml is the <depends> node :

<config>
    <modules>
        <Mymodule_Sales>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Sales />
                <Oeditor_Ordereditor />
            </depends>
        </Mymodule_Sales>
    </modules>
</config> 

See the second answer here for reference.

Be careful about managing the inheritance. You can use parent:: to pass control to Oeditor_Ordereditor and the genius of Alan Storm has a comprehensive article on using parent:: in rewrites so I think it is worth re-reading that article again.