Magento addFieldToFilter: Two fields, match as OR, not AND

后端 未结 10 1233
孤街浪徒
孤街浪徒 2020-12-04 09:42

I\'ve been stuck on this for the last few hours. I got it working by hacking a few lines in /lib/Varien/Data/Collection/Db.php, but I\'d rather use the proper s

10条回答
  •  一向
    一向 (楼主)
    2020-12-04 10:25

    To create simple OR condition for collection, use format below:

        $orders = Mage::getModel('sales/order')->getResourceCollection();
        $orders->addFieldToFilter(
          'status',
          array(
            'processing',
            'pending',
          )
        );
    

    This will produce SQL like this:

    WHERE (((`status` = 'processing') OR (`status` = 'pending')))
    

提交回复
热议问题