How can I get collection of orders with payment method 'checkmo' ? Can I do it with addFieldToFilter function?
Thanks.
use the code below :
$ordersByPaymentCheckMo = Mage::getResourceModel('sales/order_payment_collection')
->addFieldToSelect('*')
->addFieldToFilter('method',"checkmo");
foreach($ordersByPaymentCheckMo as $orderByPayment):
$order = Mage::getModel('sales/order')->load($orderByPayment->getParentId());
echo '<br/>ORDER # : '.$order->getIncrementId();
endforeach;
An Update the best way to do this is joining the collections:
$table_prefix = Mage::getConfig()->getTablePrefix();
$order_table = $table_prefix.'sales_flat_order';
$on_condition = "main_table.parent_id = $order_table.entity_id";
$orderCollection = Mage::getModel('sales/order_payment')->getCollection()->addFieldToFilter('method',"checkmo");
$orderCollection ->getSelect()->join($order_table,$on_condition);
foreach($orderCollection as $order):
echo '<br/>ORDER # : '.$order->getIncrementId();
endforeach;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With