I'm trying to use a product repository to fetch a list of products. I want to fetch based on multiple filters (category_id, name, description and short description), combined with an OR criteria, but things don't seem to be working.
the idea is to search for a keyword in all product's names, descriptions and short descriptions also in categories names here is my code
$categoriesCollection = $this->categoryFactory->create();
$categoriesCollection->addAttributeToFilter('name', array(array('like' => '%' . $term . '%')));
$categoriesIds = $categoriesCollection->exportToArray();
$filter1 = $this->filterBuilder->setField('name')
->setValue("%$term%")
->setConditionType('like')
->create();
$filter2 = $this->filterBuilder->setField('description')
->setValue("%$term%")
->setConditionType('like')
->create();
$filter3 = $this->filterBuilder->setField('short_description')
->setValue("%$term%")
->setConditionType('like')
->create();
$filter4 = $this->filterBuilder->setField('category_id')
->setValue(array_keys($categoriesIds))
->setConditionType('in')
->create();
$filter_group1 = $this->filterGroupBuilder
->addFilter($filter1)
->addFilter($filter2)
->addFilter($filter3)
->addFilter($filter4)
->create();
$search_criteria = $this->searchCriteriaBuilder->setFilterGroups([$filter_group1])
->setPageSize($pageSize)->setCurrentPage($currentPage)->create();
$list = $this->getList($search_criteria);
the filter works fine when I remove the others filters except category, but doesn't work when all filters are combined as above.
Is there a problem in my code? and how can I achieve this?
category_ids
instead ofcategory_id