Magento 1.8 – Remove Existing WHERE Clauses from $collection->getSelect()

collection;magento-1.8query

I am trying to modify the Lifetime Sales figure on the admin landing page to include pending_payment orders. I have set up a module as follows:

class Steamdesk_Dashboard_Block_Dashboard_Sales extends Mage_Adminhtml_Block_Dashboard_Sales

And I have the following to set a suitable WHERE clause in the SQL for the collection:

$collection->getSelect()->where('main_table.state NOT IN (?)', array(
        Mage_Sales_Model_Order::STATE_CLOSED,
        Mage_Sales_Model_Order::STATE_CANCELED
    )
);

However there are already two elements in the WHERE clause array which will cause the above to be ignored, which I can see if I check $collection->getSelect() as follows:

[where] => Array
(
    [0] => (main_table.status NOT IN('canceled'))
    [1] => AND (main_table.state NOT IN('new', 'pending_payment'))
)

I know all this code is being run, but my question is how can I clear the existing attributes in the collection's generated SQL query?

Best Answer

Simply add $collection->clear()->getSelect()->reset(\Zend_Db_Select::WHERE); to your code above your Query.

Related Topic