2

I'm stuck on something, I've look on every results I have found on Google but I haven't found the solution yet.

I'm trying to do a SQL request which look like that:

SELECT `main_table`.*, `order`.`increment_id` AS `order_increment_id`, `order`.`status` AS `order_status` FROM `magentoudropship_po` AS `main_table`
INNER JOIN `magentosales_flat_order` AS `order` ON main_table.order_id=order.entity_id
WHERE ((main_table.udropship_status = 0 AND main_table.created_at > '22/04/2015') OR (main_table.udropship_status = 9 AND main_table.created_at > '20/04/2015'))

I haven't found how to insert an AND condition inside a OR condition ...

Here's my actual code:

$collection = Mage::getModel('udpo/po')->getCollection()
            ->addFieldToFilter(
                array('main_table.udropship_status', 'main_table.udropship_status'),
                array(array('eq' => Unirgy_DropshipPo_Model_Source::UDPO_STATUS_PENDING), array('eq' => Unirgy_DropshipPo_Model_Source::UDPO_STATUS_ACK))
            );
$collection->getSelect()->join(
            array('order' => Mage::getSingleton('core/resource')->getTableName('sales/order')), 'main_table.order_id=order.entity_id',
            array('order_increment_id' => 'increment_id', 'order_status' => 'status')
        );
$collection->load();

And this is the request I have for now:

SELECT `main_table`.*, `order`.`increment_id` AS `order_increment_id`,  `order`.`status` AS `order_status` FROM `magentoudropship_po` AS `main_table`
INNER JOIN `magentosales_flat_order` AS `order` ON  main_table.order_id=order.entity_id
WHERE ((main_table.udropship_status = 0) OR (main_table.udropship_status = 9))

Do you know how to achieve a condition like ((condition AND condition) OR (condition AND condition)) ?

1
  • Have you tried achieving your AND-OR condition using Zend_Db_Select's methods?
    – laketuna
    Commented Apr 23, 2015 at 18:42

1 Answer 1

1

Try this

$collection->getSelect()
->orWhere('condition1 AND condition2')
->orWhere('condition3 AND condition4')

Then bind the params in your conditions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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