first of all, I apologize for asking yet another "magento core override" question here, but I followed about 10 tutorials and read through almost all similar questions posted here, no success.
I have to override a bunch of core models and classes. The code works, because I already changed the core (in a test magento site) and it worked perfect. But every now and then a magento update is available and if we would apply the updates all of my changes would be lost. So I have to override the base code instead. I want to make my own module to put in all of the required code, because I only have to override 1 or 2 functions in every class, the rest should work like Magento intended.
My first attempt was to override the Mage_Sales_Model_Order_Pdf_Invoice class. Ok, so I made my module. The file structure is:
app/code/local/[namespace]/Sales/etc/config.xml
app/code/local/[namespace]/Sales/Helper/Data.php (This class doesn't do anything, it's just an empty class. I made it because I read somewhere that Magento sometimes doesn't recognize the module if there is no Helper class)
app/code/local/[namespace]/Sales/Model/Order/Pdf/Invoice.php
app/etc/modules/[namespace]_Sales.xml
The [namespace]_Sales.xml file looks this way:
<?xml version="1.0"?>
<config>
<modules>
<[namespace]_Sales>
<active>true</active>
<codePool>local</codePool>
</[namespace]_Sales>
</modules>
</config>
The config.xml file looks like this:
< ?xml version="1.0"?>
<config>
<modules>
<[namespace]_Sales>
<version>0.1.0</version>
</[namespace]_Sales>
</modules>
<global>
<helpers>
<sales>
<class>[namespace]_Sales_Helper</class>
</sales>
</helpers>
<models>
<sales>
<rewrite>
<order_pdf_invoice>[namespace]_Sales_Model_Order_Pdf_Invoice</order_pdf_invoice>
</rewrite>
</sales>
</models>
</global>
</config>
And the Invoice.php file looks like this:
<?php
/****I'm adding some different classes here*******************************/
include_once Mage::getBaseDir('lib')."/myclass.php";
include_once Mage::getBaseDir('lib')."/another_library.php";
/********************************************************/
class [namespace]_Sales_Model_Order_Pdf_Invoice extends Mage_Sales_Model_Order_Pdf_Invoice
{
public function getPdf($invoices = array())
{
//my code
}
}
I wanted to test this first before I go and override all the other controllers and models I have to change.
The problem is, it still uses the original model.
I think the module code and paths are correct, because magento finds my custom model. I checked by going into the backend and looked at System->configuration->advanced
I cleared the cache completely, so that's not it.
I used get_class to determine what model is returned in the controller: get_class(Mage::getModel('sales/order_pdf_invoice')), this returns Mage_Sales_Model_Order_Pdf_Invoice
I do not know where I made a mistake but I am sure I made one :(
< ?xml version="1.0"?>
– Dmytro Zavalkin