Note that there are some explanatory texts on larger screens.

plurals
  1. POmagento cannot override core model
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>My first attempt was to override the <strong>Mage_Sales_Model_Order_Pdf_Invoice</strong> class. Ok, so I made my module. The file structure is:</p> <p><strong>app/code/local/[namespace]/Sales/etc/config.xml</strong></p> <p><strong>app/code/local/[namespace]/Sales/Helper/Data.php</strong> (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)</p> <p><strong>app/code/local/[namespace]/Sales/Model/Order/Pdf/Invoice.php</strong></p> <p><strong>app/etc/modules/[namespace]_Sales.xml</strong></p> <p>The [namespace]_Sales.xml file looks this way:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;config&gt; &lt;modules&gt; &lt;[namespace]_Sales&gt; &lt;active&gt;true&lt;/active&gt; &lt;codePool&gt;local&lt;/codePool&gt; &lt;/[namespace]_Sales&gt; &lt;/modules&gt; &lt;/config&gt; </code></pre> <p>The config.xml file looks like this:</p> <pre><code>&lt; ?xml version="1.0"?&gt; &lt;config&gt; &lt;modules&gt; &lt;[namespace]_Sales&gt; &lt;version&gt;0.1.0&lt;/version&gt; &lt;/[namespace]_Sales&gt; &lt;/modules&gt; &lt;global&gt; &lt;helpers&gt; &lt;sales&gt; &lt;class&gt;[namespace]_Sales_Helper&lt;/class&gt; &lt;/sales&gt; &lt;/helpers&gt; &lt;models&gt; &lt;sales&gt; &lt;rewrite&gt; &lt;order_pdf_invoice&gt;[namespace]_Sales_Model_Order_Pdf_Invoice&lt;/order_pdf_invoice&gt; &lt;/rewrite&gt; &lt;/sales&gt; &lt;/models&gt; &lt;/global&gt; &lt;/config&gt; </code></pre> <p>And the Invoice.php file looks like this:</p> <pre><code>&lt;?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 } } </code></pre> <p>I wanted to test this first before I go and override all the other controllers and models I have to change.</p> <p>The problem is, it still uses the original model. </p> <p>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 <strong>System->configuration->advanced</strong></p> <p>I cleared the cache completely, so that's not it.</p> <p>I used get_class to determine what model is returned in the controller: <strong>get_class(Mage::getModel('sales/order_pdf_invoice'))</strong>, this returns <strong>Mage_Sales_Model_Order_Pdf_Invoice</strong></p> <p>I do not know where I made a mistake but I am sure I made one :(</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload