1

I am developing a cron supposed to capture all the recent orders from a specific payment method, but I currently have a problem getting all the orders from a specific payment method.

I thought that the payment method would be in the sales_flat_order table, but it isn't, so I can not use something like :

$ordersCollection = Mage::getModel('sales/order')->getCollection() ->addFieldToFilter('payment_method', $paymentMethod); 

How can I filter all the orders and only get the one with a certain payment method ?

2 Answers 2

1

Try to do this using 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',"PAYMENT_METHOD_NAME"); // for e.g checkmo $orderCollection ->getSelect()->join($order_table,$on_condition); foreach($orderCollection as $order): echo '<br/>ORDER # : '.$order->getIncrementId(); endforeach; 

Hope this will help!

0

Try following code:

 $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; 

Hope this work for you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.