Skip to main content
1 of 2

Magento resource Collection override

I have been trying to override Magento resource collection class. I have found few solutions but it seems can't get it to work.
The class is located in:

App/code/core/Mage/Reports/Model/Resource/Order/Collection.php

This is the code to register module:

<?xml version="1.0"?> 
    <config>  
        <modules>  
            <XYZ_Reports>
                <active>true</active>  
                <codepool>local</codepool>  
            </XYZ_Reports>
        </modules>  
    </config> 

And XML config file to override collection:

<?xml version="1.0"?>
<config>
    <modules>
        <XYZ_Reports>
            <version>0.1.0</version>
        </XYZ_Reports>
    </modules>
    <global>
        <models>
            <reports>
                <rewrite>
                    <resource_order_collection>
                        XYZ_Reports_Model_Resource_Order_Collection
                    </resource_order_collection>
                </rewrite>
            </reports>
        </models>
    </global>    
</config>

This is a one version of config file. I have used different approaches including this one suggested by Damir Korpar - Inchoo:

<?xml version="1.0"?>
<config>
    <modules>
        <XYZ_Reports>
            <version>0.1.0</version>
        </XYZ_Reports>
    </modules>
    <global>
        <models>
            <reports_resource>
                <rewrite>
                    <order_collection>
                        XYZ_Reports_Model_Resource_Order_Collection
                    </order_collection>
                </rewrite>
            </reports_resource>
        </models>
    </global>    
</config>

The new file located in:

app/local/XYZ/Reports/Model/Resource/Order/Collection.php

And finally extended class:

<?php

class XYZ_Reports_Model_Resource_Order_Collection extends Mage_Reports_Model_Resource_Order_Collection
{
    
    public function joinCustomerName($alias = 'name')
    {
        die('Overridden class'); 
    }
}