Magento 2 : Condition Type in Search Filter

Today we are going to keep it just short and sweet to help our Magento 2 developers to find out what all condition types are available in Magento 2 -:

“eq” => EqualValue

“neq” => notEqualValue

“like” => likeValue

“nlike” => notLikeValue

“is” => isValue

“in” => inValues

“nin” => notInValues

“notnull” => valueIsNotNull

“null” => valueIsNull

“moreq” => moreOrEqualValue

“gt” => greaterValue

“lt” => lessValue

“gteq” => greaterOrEqualValue

“lteq” => lessOrEqualValue

“finset” => valueInSet

“from” => fromValue

“to” => toValue

Quick example to extract order data with the help of Magento 2 using filter builder, search criterial builder and condition types

$eqFilter = $this->filterBuilder
            ->setField('custom_attribute')
            ->setValue(1)
            ->setConditionType('eq')
            ->create();
$statusFilter = $this->filterBuilder
            ->setField('status')
            ->setValue(array('pending','processing'))
            ->setConditionType('in')
            ->create();
filterBuilder – \Magento\Framework\Api\FilterBuilder $filterBuilder

$searchCriteria = $this->searchCriteriaBuilder
            ->addFilters([$eqFilter, $statusFilter])
            ->create();
searchCriteriaBuilder – \Magento\Framework\Api\SearchCriteriaBuilder

$orders = $this->orderRepository->getList($searchCriteria);
orderRepository – \Magento\Sales\Api\OrderRepositoryInterface $orderRepository

That’s it, Hope this article helped you in some way. Please leave us your comment and let us know what do you think? Thanks.

Scommerce

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.