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)

Problem is my method did not call. I wrote a script to make sure that Magento knows about my class:

require 'app/Mage.php';


$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?


I have a long config.xml file and I don't think it's necessary to paste it here. But here's models part:

  • Post your config.XML file – MeenakshiSundaram R Aug 1 '15 at 16:34
  • What's the output of var_dump(get_class(Mage::getResourceModel('sales/report_order_collection')));? – Adi Aug 1 '15 at 23:24
  • @AdrianCiobanu it's Mage_Sales_Model_Resource_Report_Order_Collection – Pedram Behroozi Aug 2 '15 at 4:45
  • Yup, you were overwriting the model, instead of the resource model, like @MeenakshiSundaramR said. – Adi Aug 2 '15 at 10:35

You are rewrite the resource model. So you have to rewrite like below.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.