Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Problem overloading an abstract resource class
 
egabbud
Jr. Member
 
Total Posts:  10
Joined:  2008-07-16
 

I’m trying to overload Mage_Catalog_Model_Resource_Eav_Mysql4_Collection_Abstract which is in Catalog/Model/Resource/Eav/Mysql4/Collection/Abstract.php

I’ve activated my new module in /app/etc/modules/MyCompany_Catalog.xml:

<?xml version="1.0"?>
<config>
    <
modules>
        <
MyCompany_Catalog>
            <
active>true</active>
            <
codePool>local</codePool>
            <
version>0.7.57</version>
        </
MyCompany_Catalog >
    </
modules>
</
config>

Then I defined the module in /app/code/local/MyCompany/Catalog/etc/config.xml:

<?xml version="1.0"?>
<config>
    <
modules>
        <
QCNS_Catalog>
            <
version>0.7.57</version
        </
QCNS_Catalog>
    </
modules>
    
    <global>
        <
models>
           <
catalog>
                <
rewrite>
<
resource_eav_mysql4_collection_abstract>MyCompany_Catalog_Model_Resource_Eav_Mysql4_Collection_Abstract</resource_eav_mysql4_collection_abstract>
                </
rewrite>
            </
catalog>
        </
models>
    </global>
</
config>

So far this file is parsed (I get an error if I make it non-XML compliant).

Then I overloaded my class in /app/code/local/MyCompany/Catalog/Model/Resource/Eav/Mysql4/Collection/Abstract.php:

class MyCompany_Catalog_Model_Resource_Eav_Mysql4_Collection_Abstract extends Mage_Catalog_Model_Resource_Eav_Mysql4_Collection_Abstract
{
    
protected function _getLoadAttributesSelect($table)
    
{
        
// my custom code here
    
}
}

Problem: this class file is never loaded (if I make it non-PHP compliant, it doesn’t crash).
What am I missing to overload this class?

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

you cant overload abstract classes, make your cutomization in class which extends the abstract.

cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
egabbud
Jr. Member
 
Total Posts:  10
Joined:  2008-07-16
 

Ok so as I can’t overload the abstract class, I’m trying now with Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection which extends the abstract one.

So now I have code/local/MyCompany/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php where I try to overload _getLoadAttributesSelect($table) (which is only defined in the Abstract class).

I changed the config.xml file to have something like this instead:

<global>
        <
models>
           <
catalog>
                <
rewrite>
<
resource_eav_mysql4_product_collection>MyCompany_Catalog_Model_Resource_Eav_Mysql4_Product_Collection</resource_eav_mysql4_product_collection>
               </
rewrite>  
            </
catalog>
        </
models>
    </global>

but it’s still not working… I can overload other classes easily (like Product), but not that one… this is driving me crazy…

Thanks for your help!

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

xml should look like this:

<global>
        <
models>
           <
catalog_resource_eav_mysql4>
                <
rewrite>
                    <
product_collection>MyCompany_Catalog_Model_Resource_Eav_Mysql4_Product_Collection</product_collection>
               </
rewrite>  
            </
catalog_resource_eav_mysql4>
        </
models>
    </global>

check the config.xml of catalog module, there you find:

<snippet>

<models>
            <
catalog>
                <class>
Mage_Catalog_Model</class>
                <
resourceModel>catalog_resource_eav_mysql4</resourceModel>
            </
catalog>

            <
catalog_resource_eav_mysql4>
                <class>
Mage_Catalog_Model_Resource_Eav_Mysql4</class>
                <
entities>
                    <
product>
                        <
table>catalog_product_entity</table>
                    </
product>
</snippet>

cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
egabbud
Jr. Member
 
Total Posts:  10
Joined:  2008-07-16
 

Oh I finally get it!! Thank you so much!

I tried lot of combinations, but somehow missed that one… Thanks for your help!

 
Magento Community Magento Community
Magento Community
Magento Community
 
amine2005
Jr. Member
 
Total Posts:  23
Joined:  2008-09-11
 

.

 
Magento Community Magento Community
Magento Community
Magento Community
 
gabi
Jr. Member
 
Total Posts:  10
Joined:  2008-10-02
 

I’m trying to overload Mage_Catalog_Block_Product_Abstract which is in app\code\core\Mage\Catalog\Block\Product
but how to declare it in myModule in config.Xml ??????????????

 
Magento Community Magento Community
Magento Community
Magento Community
 
gabi
Jr. Member
 
Total Posts:  10
Joined:  2008-10-02
 

I’m trying to overload Mage_Catalog_Block_Product_Abstract which is in app\code\core\Mage\Catalog\Block\Product
but how to declare it in myModule in config.Xml ??????????????

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

better overload not the abstract, it wount work. better overload the correspondig block you want to individualize.

<blocks>    
            <
catalog>
                <
rewrite>
                    
                    <
product_list>Mage_MyModule_Block_Catalog_Product_List</product_list>
                    <
product_view>Mage_MyModule_Block_Catalog_Product_View</product_view>
                    
                </
rewrite>
            </
catalog>        
</
blocks>

This is an example for overloading list and view block of product.

cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
miked2004
Sr. Member
 
Avatar
Total Posts:  214
Joined:  2007-12-13
Atlanta, Georgia
 

Thank you so much for this post. I was going crazy trying to do this and after reading this once It worked!!!!!!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

welcome smile

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top