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

natanael

New Member
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 solution and leave my core untouched.All I need to do is get a collection and filter it by two or more fields. Say, customer_firstname and remote_ip. Here's my (disfunctional without hacking Db.php) code:\[code\]$collection = Mage::getModel('sales/order')->getCollection()->addAttributeToSelect("*")->addFieldToFilter(array(array('remote_ip', array('eq'=>'127.0.0.1')),array('customer_firstname', array('eq'=>'gabe'))), array('eq'=>array(1,2,3)));\[/code\]With a stock Db.php, I tried this: (sample taken from http://magentoexpert.blogspot.com/2009/12/retrieve-products-with-specific.html)\[code\]$collection->addFieldToFilter(array( array('name'=>'orig_price','eq'=>'Widget A'), array('name'=>'orig_price','eq'=>'Widget B'), ));\[/code\]But that gives me this error:\[code\]Warning: Illegal offset type in isset or empty in magento/lib/Varien/Data/Collection/Db.php on line 369\[/code\]If I wrap that with a try/catch, then it moves into _getConditionSql() and gives this error:\[code\]Warning: Invalid argument supplied for foreach() in magento/lib/Varien/Data/Collection/Db.php on line 412\[/code\]Does anyone have any working, functional code for doing this? I'm running Magento 1.9 (Enterprise). Thanks!
 
Back
Top