1

I have the following code:

$filter1 = $this->_filterBuilder->setField('name')
    ->setValue('%'.$searchTerm.'%')
    ->setConditionType("like")
    ->create();
$filter2 = $this->_filterBuilder->setField('description')
    ->setValue('%'.$searchTerm.'%')
    ->setConditionType("like")
    ->create();
$filterOR = $this->_filterGroupBuilder->addFilter($filter1)->addFilter($filter2)->create();
$this->_searchCriteriaBuilder->setFilterGroups([$filterOR]);
$this->_searchCriteriaBuilder->addSortOrder($searchOrder, SortOrder::SORT_ASC);
$searchCriteria = $this->_searchCriteriaBuilder->setCurrentPage($page)->setPageSize($pageSize)->create();
$searchResults = $this->_productRepository->getList($searchCriteria);

It throws an error:

Call to undefined method Magento\Framework\Api\Search\SearchCriteriaBuilder::setFilterGroups()

why?

1
  • simple....there is no method setFilterGroups in the class Magento\Framework\Api\Search\SearchCriteriaBuilder
    – Marius
    Jun 26 '17 at 16:19
2

There is no method setFilterGroups in the class Magento\Framework\Api\Search\SearchCriteriaBuilder
Not sure if this will work but you can try to remove the line that contains setFilterGroups and after the line

$searchCriteria = $this->_searchCriteriaBuilder->setCurrentPage($page)->setPageSize($pageSize)->create();

add this

$searchCriteria->setFilterGroups([$filterOR]);  

there is a mehtod setFilterGroups in Magento\Framework\Api\SearchCriteriaInterface and SearchCriteria class.

2
  • how can i reset the builder to create a new after?
    – Miguel
    Jun 26 '17 at 16:35
  • sorry, I don't know.
    – Marius
    Jun 26 '17 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.