过去几个小时我一直坚持这个.我通过乱砍几行来解决这个问题/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)));
Run Code Online (Sandbox Code Playgroud)
有了股票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'),
));
Run Code Online (Sandbox Code Playgroud)
但这给了我这个错误:
Warning: Illegal offset type in isset or empty in magento/lib/Varien/Data/Collection/Db.php on line 369
Run Code Online (Sandbox Code Playgroud)
如果我用try/catch包装它,那么它会进入_getConditionSql()并给出这个错误:
Warning: Invalid argument supplied for foreach() in magento/lib/Varien/Data/Collection/Db.php on line 412
Run Code Online (Sandbox Code Playgroud)
有没有人有任何工作,功能代码这样做?我正在运行Magento 1.9(企业版).谢谢!
我想通过在Collection中应用OR条件从表中获取数据
我正在使用这些代码行
$ collect =法师:: getModel('storelocater / storelocater')-> getCollection()-> addFieldToFilter(array(
数组(
'attribute'=>'country',
'eq'=>'印度'),
数组(
'attribute'=>'state',
'eq'=>'上')
));
echo $ data = $ collect-> getSelect();
它输出输出
SELECT main_table。* FROM storelocaterAS main_tableWHERE((Array ='')或(Array =''))
我还使用了addAttributeToFilter而不是addFieldToFilter,但是它返回致命错误