I am doing the following to get some orders out of the system for export:
$orders = Mage::getModel('sales/order')->getCollection() ->addFieldToFilter('status', $statusToExport) ->addFieldToFilter('store_id', $this->processingStoreId) ->addFieldToFilter('updated_at', array('gteq' => date('Y-m-d H:i:s', $lastSyncTime))); I need to add something in where it doesn't export if the order entity_id is in a custom table I have. If I was using SQL, I would do:
left join myTable as mt on main_table.entity_id = mt.entity_id where mt.entity_id is null But I am not sure how to modify the collection query to do a similar thing.
Note: I did try
$orders = $orders->getSelect() ->joinLeft( array("t1" => $myTable), "main_table.entity_id = t1.entity_id", array("admin_field_id" => "t1.id") ) ->where("t1.id is null") but this changes it so it's a query and I want the sales/order collection returned.
I feel I am missing something simple ...
EDIT
Ok, I have tried this:
$orders->getSelect() ->joinLeft( array("t1" => $myTable), "main_table.entity_id = t1.entity_id", array("admin_field_id" => "t1.id") ) ->where("t1.id is null"); When I echo (string)$orders->getSelect() it returns the query I would expect and returns no results when I run it. $orders however, still contains items. I thought this join was meant to modify the collection at this point?