0

I need to do exactly I asked in the question.

I have overrided the reports generation file app/code/core/Mage/Adminhtml/Adminhtml/Block/Report/Sales/Sales/Grid.php to app/code/local/Mage/Adminhtml/Adminhtml/Block/Report/Sales/Sales/Grid.php.

Now I want to print the query that is being generated but I am clueless when I see the ResourceModel is set dynamically like below:

public function getResourceCollectionName()
    {   
        return ($this->getFilterData()->getData('report_type') == 'updated_at_order')
            ? 'sales/report_order_updatedat_collection'
            : 'sales/report_order_collection';
    }

I modified this function like below but in vain:

public function getResourceCollectionName()
    {   
        $resCollName = ($this->getFilterData()->getData('report_type') == 'updated_at_order')
            ? 'sales/report_order_updatedat_collection'
            : 'sales/report_order_collection';
        echo Mage::getResourceModel($resCollName)->getSelect();die;
        return $resCollName;
    }

How to print query generated in this function so I don't have to override the Abstract.php file ?

2 Answers 2

2

Use this

echo $collection->getSelect()->__toString();

if you want to log then add below syntax:

$collection->printLogQuery(false, true);
2

you can use below syntax to print SQL query.

echo $collection->getSelect();
5
  • But if you seen that file, there is no $collection object being used there, just the resource collection function name is declared and the columns are getting data without setting collection probably.
    – Vicky Dev
    Commented Jul 4, 2016 at 5:20
  • 1
    As per your requirement, collection is loaded in app/code/core/Mage/Adminhtml/Block/Report/Grid/Abstract.php file. in _prepareCollection() function collection is loaded. Commented Jul 4, 2016 at 5:28
  • Any chance I could print query in this file and function without need to put Abstract.php in local directory ?
    – Vicky Dev
    Commented Jul 4, 2016 at 5:34
  • Any idea where this sql query is written? Can I check that sql query?
    – Pankaj
    Commented Apr 2, 2018 at 19:11
  • stackoverflow.com/questions/49597827/…
    – Pankaj
    Commented Apr 2, 2018 at 19:12

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.