我在这个问题上卡了几个小时。通过篡改/lib/Varien/Data/Collection/Db.php
中的几行代码,我已经解决了它,但我更倾向于使用正确的解决方案并保持我的核心代码不变。
我只需要获取一个集合并按两个或更多字段进行过滤。比如说,customer_firstname
和remote_ip
。这是我的(在没有篡改Db.php
的情况下无法正常工作的)代码:
$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)));
我使用了原始的Db.php
,并尝试了以下操作:(示例取自http://magentoexpert.blogspot.com/2009/12/retrieve-products-with-specific.html)
$collection->addFieldToFilter(array(
array('name'=>'orig_price','eq'=>'Widget A'),
array('name'=>'orig_price','eq'=>'Widget B'),
));
但是这会给我带来以下错误:
Warning: Illegal offset type in isset or empty in magento/lib/Varien/Data/Collection/Db.php on line 369
如果我将其包装在try/catch中,那么它就会移动到_getConditionSql()并产生此错误:If I wrap that with a try/catch, then it moves into _getConditionSql() and gives this error:
Warning: Invalid argument supplied for foreach() in magento/lib/Varien/Data/Collection/Db.php on line 412
有没有人有可用的、实用的代码来做这件事?我正在运行 Magento 1.9(企业版)。谢谢!
... WHERE (('first_attribute' = 'some value') OR ('second_attribute' = 'some value'))
- Mageician