Magento – Magento 2: How to change Advanced Search from “AND” to “OR”

advanced-searchcatalogsearchmagento2searchsearch-criteria

I'm stuck with this situation:

I have 2 select-type attributes: A and B for example
In both of the attributes, I have the same list of Options (but they are different option ids)

For example
In attribute A, I have these options:
Option_1, option id = 1
Option_2, option id = 2
Option_3, option id = 3

In attribute A, I have these options:
Option_1, option id = 4
Option_2, option id = 5
Option_3, option id = 6

Now I have this advanced search query for "Option_1": http://domain/catalogsearch/advanced/result/?A[]=1&B[]=3
But what I want is:

The Product 1 (has A = Option 1, with id 1)
The Product 2 (has B = Option 1, with id 4)

Because advanced search use "AND" then this return zero result.

Can it use "OR" to return both Product 1 and Product 2? Or any solution for my situation?

Maybe this also the search Query is ?A[]=1, but it still return the product which has B[]=4

I hope this question is clear.

Best Answer

First copy this file in your code/local with same directory structure app/code/core/Mage/CatalogSearch/Model/Resource/Advanced/Collection.php

Then Replace this code :

if (!is_null($previousSelect)) {
    $select->where('t1.entity_id IN (?)', new Zend_Db_Expr($previousSelect));
}

With (change where => orWhere) :

if (!is_null($previousSelect)) {
    $select->orWhere('t1.entity_id IN (?)', new Zend_Db_Expr($previousSelect));
}
Related Topic