在Magento的复杂的布尔条件 [英] complex boolean conditions on Magento

查看:191
本文介绍了在Magento的复杂的布尔条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到在Magento的教程解决这个问题。
我怎样才能实现定制机型OR运算符有两个属性涉及到什么时候?在官方教程中的示例演示仅使用或布尔的一个字段,SKU。

I cannot find the solution to this problem in magento tutorials. How can I implement the boolean OR operator in custom models when there are two attributes involved? The example in the official tutorial only demonstrated the use of OR boolean for one field, sku.

$filter_a = array('like'=>'a%');
$filter_b = array('like'=>'b%');

Mage::getModel('catalog/product')
->getCollection()
->addFieldToFilter('sku', array($filter_a, $filter_b))
->getSelect();

这相当于

WHERE e.sku like 'a%' or e.sku like 'b%' 

但是,如果我需要运行诸如条件的内容:

But what if I need to run conditions such as :

 WHERE   (e.sku like 'a%' or e.sku like 'b%')  or  (table_price.value >= '10' ) 

我怎么能做到这一点的Magento的?谢谢

How can I do this on Magento? Thanks

推荐答案

你有你的语法incorrec,试试这个:

You have your syntax incorrec, try this:

Mage::getModel('catalog/product')
->getCollection()
->addAttributeToFilter(
    array(
        array('attribute'=>'firstname', 'like'=>'test%'),
        array('attribute'=>'lastname', 'like'=>'test%'),
    )
)

您可以通过SKU或什么都你想更换属性名称。每个数组项将被OR操作。

you could replace the attribute names by 'sku' or what ever you wanted. Each array entry will be OR'd.

这篇关于在Magento的复杂的布尔条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆