0

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>
4
  • Post your config.XML file Commented Aug 1, 2015 at 16:34
  • What's the output of var_dump(get_class(Mage::getResourceModel('sales/report_order_collection')));?
    – Adi
    Commented Aug 1, 2015 at 23:24
  • @AdrianCiobanu it's Mage_Sales_Model_Resource_Report_Order_Collection Commented Aug 2, 2015 at 4:45
  • Yup, you were overwriting the model, instead of the resource model, like @MeenakshiSundaramR said.
    – Adi
    Commented Aug 2, 2015 at 10:35

1 Answer 1

2

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

<models>
   <sales_resource> 
      <rewrite>
          <report_order_collection>Namespace_Module_Model_Sales_Resource_Report_Order_Collection</report_order_collection>
      </rewrite> 
    </sales_resource>
</models>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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