Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Magento“;addAttributeToFilter类似“添加属性”;带有或不起作用的语句_Php_Magento_Filter_Sql Like_Addattribute - Fatal编程技术网

Php Magento“;addAttributeToFilter类似“添加属性”;带有或不起作用的语句

Php Magento“;addAttributeToFilter类似“添加属性”;带有或不起作用的语句,php,magento,filter,sql-like,addattribute,Php,Magento,Filter,Sql Like,Addattribute,我正在做一个Magento项目,但我真的卡住了 我想在我的查询中添加两个LIKE检查 现在,我的代码如下所示: $this->_productCollection->addAttributeToFilter( array( array('attribute' => 'name', 'like' => '%'.$_GET["keyword"].'%'), array('attribute' => 'att_wine_alias'

我正在做一个Magento项目,但我真的卡住了

我想在我的查询中添加两个LIKE检查

现在,我的代码如下所示:

$this->_productCollection->addAttributeToFilter(
    array(
        array('attribute' => 'name', 'like' => '%'.$_GET["keyword"].'%'),
        array('attribute' => 'att_wine_alias', 'like' => '%'.$_GET["keyword"].'%')
    )
);
附件葡萄酒别名: 有拼写错误或标记的文本区域

所以,如果我使用这段代码,Magento不会在name字段中搜索。如果我从过滤器中删除att\u wine\u alias属性,name搜索工作正常

我想使用OR语句在两个字段中搜索

我做错了什么

谢谢
//很抱歉出现英语错误

请尝试下面的代码,并告诉我这是否有效

$this->_productCollection->addAttributeToFilter(
    array(
         array('attribute' => 'name', 'like' => $_GET["keyword"]),
         array('attribute' => 'att_wine_alias', 'like' => $_GET["keyword"])
    )
);
但是,addFieldToFilter也是一个选项,其工作方式如下:

->addFieldToFilter(
    array('name', 'att_wine_alias'),
    array(
        array('like'=>'%' . $GET['keyword'] . '%'), 
        array('like'=>'%' . $GET['keyword'] . '%')
    )
 )
下面评论中提到的错误可能是因为重新编制了索引。你用的是平板桌子吗

以防万一,如果您是,那么您可能希望重新编制索引,然后再试一次

此外,这可能是因为代码必须以这种方式放置在文件中。如果您可以在尝试编写此代码的地方共享函数,将有助于调试它

希望这有帮助

快乐编码…

好的,第一个(没有%标记)不返回任何内容。第二个返回mysql错误:“where子句”中的未知列“e.n”(我重新索引了所有内容)。我对我们的表(平面或非平面)没有任何概念,但我们将使用标准SQL查询创建一个自定义视图。再次感谢您,也很高兴为您编码。