0

I am trying to get the orders from a few conditions:

1) If order status equals 'betaald' OR 'readyforexport'

2) If payment method equals 'banktransfer' AND order status equals 'pending'

I got the first one working but I need the second one to work aswell.

My code:

$orders = Mage::getModel('sales/order')->getCollection()
->join(
    array('payment' => 'sales/order_payment'),
    'main_table.entity_id=payment.parent_id',
    array('payment_method' => 'payment.method')
)
->addAttributeToSelect('*')
->addFieldToFilter('status', 'payment.method',
    array(
        array('eq', 'betaald'),
        array('eq', 'readyforexport'),
    ),
    array(
        array('eq', 'banktransfer')
    )
)   
->addFieldToFilter('created_at', array(
'from'     => strtotime('-1 day', time()),
'to'       => time(),
'datetime' => true
))
->load();

How should my addFieldToFilter be build?

0

Try below code

$pendingOrders = Mage::getModel('sales/order')->getCollection()
    ->addFieldToFilter('status', array('in' => array('pending','pending_payment')));
$orders = $pendingOrders
->join(
    array('payment' => 'sales/order_payment'),
    'main_table.entity_id=payment.parent_id',
    array('payment_method' => 'payment.method')
)
->addAttributeToSelect('*')
->addFieldToFilter('status', 'payment.method',
    array(
        array('eq', 'betaald'),
        array('eq', 'readyforexport'),
    ),
    array(
        array('eq', 'banktransfer')
    )
)   
->addFieldToFilter('created_at', array(
'from'     => strtotime('-1 day', time()),
'to'       => time(),
'datetime' => true
))
->load();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.