What are the allowed condition types in Magento 2?
-
10-10-2020 - |
Question
What is the list of allowed condition types while adding filter to search criteria in Magento 2?
All of the examples about search criteria in the internet use eq
condition type. Is there any other? Do you have a complete list somewhere?
EDIT 1: Please look at the following code block. What are my options for condition_type?
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
$productRepository = $objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
/** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder */
$searchCriteriaBuilder = $objectManager->get(\Magento\Framework\Api\SearchCriteriaBuilder::class);
/** @var \Magento\Framework\Api\FilterBuilder $filterBuilder */
$filterBuilder = $objectManager->get(\Magento\Framework\Api\FilterBuilder::class);
$filterSpecialPrice = $filterBuilder->setField('special_price')
->setValue('0')
->setConditionType('eq')
->create();
$searchCriteria = $searchCriteriaBuilder->addFilter($filterSpecialPrice)
->create();
$productCollection = $productRepository->getList($searchCriteria);
Solution
available conditions
"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
https://devdocs.magento.com/guides/v2.3/rest/performing-searches.html
OTHER TIPS
You can try this one as well from the document
https://devdocs.magento.com/guides/v2.3/rest/performing-searches.html
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange