Magento 2: difference between Api\SearchCriteriaBuilder and Api\Search\SearchCriteriaBuilder?
-
29-09-2020 - |
Question
Those two classes are very similar but I don't get the differences and why should one be used instead of another ?
Magento\Framework\Api\Search\SearchCriteriaBuilder
=> a handful of references in the Magento native code.Magento\Framework\Api\SearchCriteriaBuilder
=> 200+ references
To me, there must be a good reason why the first one has been created but I don't get why.
Anyone can enlight me ?
Solution
They build different objects:
Magento\Framework\Api\SearchCriteria
Magento\Framework\Api\Search\SearchCriteria
(which extends the former)
The Search/SearchCriteria
has two additional methods:
/**
* @return string
*/
public function getRequestName();
/**
* @param string $requestName
* @return $this
*/
public function setRequestName($requestName);
This request name is used by UI components to identify the search request. If I understand it correctly, the interfaces in Api/Search
are meant for actual searches by the user, while the common Api/SearchResults
and Api/SearchCriteria
interfaces are used for any repositories (i.e. collection filtering and sorting)
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange