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?
Catalog
I always try to avoid using same name as core Magento module