如何使用付款方式“checkmo”获取订单?我可以使用 addFieldToFilter 函数吗?
谢谢。
使用下面的代码:
$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;