I want to modify setDateRange
method in Mage_Reports_Model_Resource_Report_Collection_Abstract
class. I know it's not possible to override an Abstract class, so I searched for its child and it was another abstract: Mage_Sales_Model_Resource_Report_Collection_Abstract
.
I searched again and I found Mage_Sales_Model_Resource_Report_Order_Collection
. I overrode it and modified the method. So I have this code:
class Namespace_Module_Model_Sales_Resource_Report_Order_Collection
extends Mage_Sales_Model_Resource_Report_Order_Collection
{
/**
* Set date range
*
* @param mixed $from
* @param mixed $to
* @return Mage_Sales_Model_Resource_Report_Collection_Abstract
*/
public function setDateRange($from = null, $to = null)
{
var_dump('modified!');
}
}
Problem is my method did not call. I wrote a script to make sure that Magento knows about my class:
require 'app/Mage.php';
Mage::app();
$c = Mage::getModel('sales/resource_report_order_collection');
var_dump(get_class($c)); // Output: Namespace_Module_Model_Sales_Resource_Report_Order_Collection
var_dump(method_exists($c, 'setDateRange')); // Output: true
var_dump($c->setDateRange()); // Output: modified!
First, I want to know why Magento never calls my method? And second, how should I modify that method?
Update:
I have a long config.xml
file and I don't think it's necessary to paste it here. But here's models
part:
<models>
<namespace_module>
<class>Namespace_Module_Model</class>
</namespace_module>
<sales>
<rewrite>
<resource_report_order_collection>Namespace_Module_Model_Sales_Resource_Report_Order_Collection</resource_report_order_collection>
</rewrite>
</sales>
<eav>
<rewrite>
<entity_attribute_backend_datetime>Namespace_Module_Model_Eav_Entity_Attribute_Backend_Datetime</entity_attribute_backend_datetime>
</rewrite>
</eav>
<catalog>
<rewrite>
<product_attribute_backend_startdate>Namespace_Module_Model_Catalog_Product_Attribute_Backend_Startdate</product_attribute_backend_startdate>
<product_attribute_backend_startdate_specialprice>Namespace_Module_Model_Catalog_Product_Attribute_Backend_Startdate_Specialprice</product_attribute_backend_startdate_specialprice>
</rewrite>
</catalog>
</models>
var_dump(get_class(Mage::getResourceModel('sales/report_order_collection')));
?Mage_Sales_Model_Resource_Report_Order_Collection