2

I found that Magento Reports module is very tricky and confusing to debug.

Though I got that the Reports > Product > Products Ordered collection is generated from Mage/Adminhtml/controllers/Report/ProductController.php soldAction, I cannot seem to get query or data for debugging purposes when I change it's Grid's (Mage_Adminhtml_Block_Report_Product_Sold_Grid) _prepareCollection to below.

protected function _prepareCollection()
    {
        parent::_prepareCollection();

        $debugCollection = $this->getCollection()->initReport('reports/product_sold_collection');
        $size = $debugCollection->getSize();
        $debug = $debugCollection->debug();
        //or
        $debugQuery = $debugCollection->getSelect();
        //or
        $debugData = $debugCollection->getData();
        $this->getCollection()->initReport('reports/product_sold_collection');
        return $this;
    }

All functions getData(), debug() & getSelect() seem to be undefined in that module class hierarchy.

  • Is solve your problem? – user51361 Jul 8 '17 at 5:40
  • Yes my problem is solved with this answer but if you still have any other easier way, then please post it here. – Vicky Dev Jul 11 '17 at 17:15
2

If you go and find the collection model in question you can always, temporarily while debugging define the _afterLoad method on the class and then do your debugging their. For example in this case if you go to the class: Mage_Reports_Model_Resource_Product_Sold_Collection and define the method:

public function _afterLoad()
{
    echo $this->getSelect();
    return parent::_afterLoad(); 
}

You will when generating a report get the query used. When you are done debugging remember to remove the code.

Hope it helps :-)

  • Thanks a lot man, I was stuck in debugging scenario, you really provided a resourceful headstart. By any chance I could do this same thing in php and add getData or getItems function to get specific columns in this same function, where do I need to define this getData for that ? – Vicky Dev Aug 20 '16 at 7:47
  • Also what is _afterLoad, can you provide some useful links for understanding that ? – Vicky Dev Aug 20 '16 at 7:53

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.