如何通过付款方式'checkmo'获取订单?我可以使用addFieldToFilter函数吗?
感谢。
答案 0 :(得分:9)
使用以下代码:
$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;
更新最佳方法是加入集合:
$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;