Magento: Overriding / Rewriting Mysql4 and Resource Eav Collection Class

Here is a tip to override/rewrite Mysql4 and Resource Eav collection class. I will only be including the config xml code. You can read more about Model Overriding over here: Magento: Model Controller Block Helper Override

By Mysql4 Collection Class, I mean like the following class:
Mage_Sales_Model_Mysql4_Order_Collection

Overriding Mysql4 Collection Class


<global>		
	<models>
		<sales_mysql4>
			<rewrite>
				<order_collection>MyNamespace_MyModule_Model_Sales_Mysql4_Order_Collection</order_collection>
			</rewrite>
		</sales_mysql4>				
	</models>
</global>

By Resource Eav Collection Class, I mean like the following class:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection

Overriding Resource Eav Collection Class


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

Checking Class Name

After overriding, you can check the class name with the following code. This is useful to check if the overriding code is correct and working or not.


echo(get_class(Mage::getResourceModel('sales/order_collection')));
echo(get_class(Mage::getResourceModel('catalog/product_collection')));

Thanks.