Question

How can I get collection of orders with payment method 'checkmo' ? Can I do it with addFieldToFilter function?

Thanks.

Was it helpful?

Solution

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top