0

As far as I know (/knew), the following 2 snippets were pretty much equivalent:

$collection = Mage::getResourceModel("reports/product_collection")

and

$collection = Mage::getModel("reports/resource_product_collection")

They both result in an instance of same class (Mage_Reports_Model_Resource_Product_Collection).

The problem comes when I try to rewrite the class. Here is how I did this:

<reports>
    <rewrite>                       
        <resource_product_collection>MyNamespace_MyModule_Model_Resource_Product_Collection</resource_product_collection>
     </rewrite>
 </reports>

This is where the difference appears, the first one isn't rewritten, while the second one is.

My questions are:

  • Is this the intended behavior ? Why ?
  • What is the difference between the 2 initial snippets ?

Note: This happens on Magento 1.7.0.2

1 Answer 1

2

Your xml should look like this:

<reports_resource>
    <rewrite>                       
        <product_collection>MyNamespace_MyModule_Model_Resource_Product_Collection</product_collection>
     </rewrite>
 </reports_resource>
2
  • +1, works perfectly this way. I do have one question however, why does my code still work in one circumstance, but not the other ?
    – Vlad Preda
    Nov 14, 2013 at 12:16
  • @VladPreda. The resource models are not meant to be instantiated with Mage::getModel. Use Mage::getResourceModel('reports/product_collection'). The fact that it works I think it's a bug/feature of the getModel method
    – Marius
    Nov 14, 2013 at 12:22

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.