2

this is a hard question to ask but I am trying to write a reporting module, following:

http://www.summasolutions.net/blogposts/custom-reports-magento.

I got that module to work on my install, but when I try to customize it or other sample reporting modules I always run up against:

"Fatal error: Call to a member function setPeriod() on a non-object in /Volumes/Apache/mage/app/code/core/Mage/Adminhtml/Block/Report/Grid.php on line 137"

One thing I know is that when I comment out my model spec in config.xml, and point the grid to a different collection like order_collection it works ok except for understandable mismatch between grid columns. Can you tell just from that what is wrong? I can pastebin files if you need it.

<models>
    <reports>
        <class>VMR_Reports_Model</class>
        <resourceModel>reports</resourceModel>
    </reports>
</models>
  • No need to pastebin the files. Add the relevant section from your config.xml as a start & we'll go from there. – benmarks May 31 '13 at 14:53
  • Moved your comment to the question. – benmarks May 31 '13 at 14:57
  • And that's under <config><global> ... </></> fyi – user2045 May 31 '13 at 14:57
  • And your resource model prefix config? – benmarks May 31 '13 at 15:01
2

You have two issues with your configuration, one local to your extension, and one which blows up Magento's core Mage_Reports module configuration.

There are three basic classes for working with / modeling an entity with Magento's ORM:

  • (Data) Model - High-level CRUD interface of one "thing"; delegates to resource model
  • Resource Model - Low-level performing CRUD of your thing; read & write access to storage
  • (Resource) Collection - For building & interacting with result set & representing multiple "things"; read-only access to storage

Both the resource model and the collection classes are defined your module's model resource folder. I suspect that currently your configuration is specifying that both models and resource models are stored in the same folder:

<models>
    <reports><!-- class group for models -->
        <class>VMR_Reports_Model</class>
        <resourceModel>reports</resourceModel>
                  <!-- ^ points to class group for resource models;
                         should be different from the model class group! -->
    </reports>
</models>

When we want a (data) model from this module (say, "report"):

Mage::getModel('reports/report');

It should be different from the resource model:

Mage::getResourceModel('reports/report');

But this only works if the value of global/models/reports/resourceModel xpath is different from the node name under global/models in which it is defined (yours currently isn't). This is really tough to describe and understand, but take my word for it. Your resourceModel value should be something ending _resource as a convention.

Your larger problem though is that normally, Mage::getModel('reports/report') will return an instance of Mage_Reports_Model_Report, because the reports class group & prefix is defined in Mage/Reports/etc/config.xml:

<global>
    <models>
        <reports>
            <class>Mage_Reports_Model</class>
            <resourceModel>reports_resource</resourceModel>
        </reports>
        <reports_resource>
            <class>Mage_Reports_Model_Resource</class>
        </reports_resource>
    </models>
 </global>

Your module, however, is overwriting the value of the global/models/reports xpath! This means that your module must implement every single class under Mage/Reports/Models/ - likely not what you are intending.

  • For context, understand that VMR is like the company, reports is the general project, and I want each controller to be 1 report. And what I am trying to do is make a custom collection that represents the report data for each report. Any suggestions on how to organize that would be appreciated. I am currently doing Model/Controllername/Collection.php – user2045 May 31 '13 at 15:59

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.