9
How do you filter the Magento Sales Order Collection by attribute1 = value1 AND (attribute2 = value2 OR attribute3 = value2)? I can write WHERE {COND1} AND {COND2} OR {COND3}, but I can't group AND ({COND2} OR {COND3})
First of all, this is not a duplicate AFAIK, I've seen this and it works great in version 1.3.2, but not in Enterprise Edition 1.11.1. Here's what I'm trying to do... get the Magento orders that were created or updated in a defined date range that have a status of 'processing'. Here is the code that works in previous versions, but not in mine:
$orderIds = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('status', 'processing')
->addFieldToFilter(array(
array(
'attribute' => 'created_at',
'from' => $fromDate->toString('yyyy-MM-dd HH:mm:ss'),
'to' => $toDate->toString('yyyy-MM-dd HH:mm:ss'),
),
array(
'attribute' => 'updated_at',
'from' => $fromDate->toString('yyyy-MM-dd HH:mm:ss'),
'to' => $toDate->toString('yyyy-MM-dd HH:mm:ss'),
),
));
This is the SQL that it's generating, and the resulting error:
SELECT `main_table`.* FROM `sales_flat_order` AS `main_table`
WHERE (status = 'processing') AND (Array = '')
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Array' in 'where clause'
In digging through the code, I found the addFieldToFilter function in lib/Varien/Data/Collection/Db.php
/**
* Add field filter to collection
*
* @see self::_getConditionSql for $condition
* @param string $field
* @param null|string|array $condition
* @return Mage_Eav_Model_Entity_Collection_Abstract
*/
public function addFieldToFilter($field, $condition=null)
{