0

Pre

I'm trying to do a very basic rewrite just to see if I can make it work. Unfortunately, no matter what class I rewrite I get fatal errors somewhere in magento.

This is my code for trying to rewrite the class Mage_Catalog_Model_Product. There are fatal errors for this in the admin panel under

Catalog/Manage Products:

Fatal error: Call to a member function getResource() on a non-object in /home/domain/public_html/magento/includes/src/Mage_Adminhtml_Block_Catalog_Product_Grid.php on line 179

and Catalog/Manage Categories:

Fatal error: Call to a member function getCollection() on a non-object in /home/domain/public_html/magento/includes/src/Mage_Adminhtml_Block_Catalog_Category_Tab_Product.php on line 76

My code

app/etc/modules/Test_Catalog.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Test_Catalog>
            <active>true</active>
            <codePool>community</codePool>
        </Test_Catalog>
    </modules>
</config>

--

app/code/community/Test/Catalog/etc/config.xml

<config>
    <global>
        <models>
            <catalog>
                <rewrite>
                    <product>Test_Catalog_Model_Product</product>
                </rewrite>
            </catalog>
        </models>
    </global>
</config>

--

app/code/community/Test/Catalog/Model/Product.php

<?php
class Test_Catalog_Model_Product extends Mage_Catalog_Model_Product {

}

My thoughts

These errors appear to go away when I delete or comment out the entire Test_Catalog.xml file. Deleting or commenting out the Product.php file keeps these errors. It's the combination of the initiator xml file in app/etc/modules/ and the config.xml having a rewrite in it. See the Edit heading.

I've tried placing a require statement above the class declaration in Product.php but these errors remained.

I originally had a function in Product.php but I took it out and the errors stayed the same.

I can add more files like the ones with the errors if anyone wants, but those are unaltered from installation.

Edit

Following this tutorial: http://code.tutsplus.com/tutorials/understand-overriding-in-magento-models--cms-23354

I now get this error under Catalog/Manage Categories

Fatal error: Call to a member function setStoreId() on a non-object in /home/domain/public_html/magento/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php on line 52

The problem is apparently something to do with the permissions(?) on my domain. I've already set mostly every permission to 755. Does anyone have an idea what specific file permissions should be changed, if this is the problem?

Through some playing around I've narrowed the problem down to specifically being the product node in config.xml. Here's an example of what causes the error and what doesn't.

<!-- This still causes the error -->
<config>
    <global>
        <models>
            <catalog>
                <rewrite>
                    <product>This_Is_Not_A_File_Path</product>
                </rewrite>
            </catalog>
        </models>
    </global>
</config>

<!-- No error -->
<config>
    <global>
        <models>
            <catalog>
               <rewrite>
                   <notproduct>Test_Cat_Model_Product</notproduct>
               </rewrite>
            </catalog>
        </models>
    </global>
</config>

Final Note

Maybe something of interest is that my Magento files don't have a local folder under code - Just community and core. Could this be caused by an incomplete installation, or is this correct for Magento version 1.9.2.4?

  • What if you change the module name to something else than Catalog I always try to avoid using same name as core Magento module – Raphael at Digital Pianism May 27 '16 at 18:24
  • It doesn't look like that was it. I changed the file name to Test_Cat.xml and put Test_Cat as the module name in that file, changed the folder name to Cat, changed the line inside the product node to Test_Cat_Model_Product, and changed the class name to Test_Cat_Model_Product. Same error. Should I be changing the catalog node in config.xml too? That doesn't make sense to me but it gets rid of the errors. I doubt the override is being run correctly then though from my understanding. – Asthmatic May 27 '16 at 18:33
  • No youre right changing IT in the config would break the rewrite. What if you disable every other local/community modules? – Raphael at Digital Pianism May 27 '16 at 18:59
  • No that still doesn't work, sorry. Sorry if you saw my last comment, I had made a mistake (changed catalog node to category by accident). Everything is written accurate to the OP again other than changing my module name to Cat instead of Catalog. – Asthmatic May 27 '16 at 19:19
0

Assuming that:

  • Your cache is disabled
  • You do not have compilation mode on

The answer is: your code is correct, problem does not come from your code.

The only possible reasons are:

  • Some typo you did not paste here
  • A permission issue (PHP process cannot read your Product.php class)

In other words Magento cannot read your Product.php class.

If you think it is a permission issue try to set everything to 777 for a test.

Remember to reset your permission once done to avoid security holes.

  • I've set everything i can find to 777 and it still gives the same error. Do you think it could be caused by an incomplete installation? Everything I've found has said I should have a local folder under code but I only have community and core. If that is missing, maybe other things important for rewriting are missing? – Asthmatic May 30 '16 at 13:35
  • Mmmm... I think an incomplete installation should give other problems... did you check for rewrite conflicts? – Phoenix128_RiccardoT May 30 '16 at 13:38
  • How would I go about checking for that? From my perspective I don't see how there would be conflicts if I'm simply extending the class – Asthmatic May 30 '16 at 13:39
  • I mean if other 3rd party modules are trying to rewrite the same class – Phoenix128_RiccardoT May 30 '16 at 15:23
  • Nope this error happens on a clean install (other than the module written above) – Asthmatic May 30 '16 at 16:21

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.