本文整理汇总了PHP中Magento\Framework\Api\SearchCriteriaBuilder::addSortOrder方法的典型用法代码示例。如果您正苦于以下问题:PHP SearchCriteriaBuilder::addSortOrder方法的具体用法?PHP SearchCriteriaBuilder::addSortOrder怎么用?PHP SearchCriteriaBuilder::addSortOrder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Api\SearchCriteriaBuilder
的用法示例。
在下文中一共展示了SearchCriteriaBuilder::addSortOrder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSearchCriteria
/**
* Creates a search criteria DTO based on the array of field filters.
*
* @return SearchCriteria
*/
protected function getSearchCriteria()
{
foreach ($this->fieldFilters as $filter) {
// array of fields, put filters in array to use 'or' group
/** @var Filter[] $filterGroup */
$filterGroup = [];
if (!is_array($filter['field'])) {
// just one field
$filterGroup = [$this->createFilterData($filter['field'], $filter['condition'])];
} else {
foreach ($filter['field'] as $index => $field) {
$filterGroup[] = $this->createFilterData($field, $filter['condition'][$index]);
}
}
$this->searchCriteriaBuilder->addFilter($filterGroup);
}
foreach ($this->_orders as $field => $direction) {
/** @var \Magento\Framework\Api\SortOrder $sortOrder */
/** @var string $direction */
$direction = $direction == 'ASC' ? SearchCriteria::SORT_ASC : SearchCriteria::SORT_DESC;
$sortOrder = $this->sortOrderBuilder->setField($field)->setDirection($direction)->create();
$this->searchCriteriaBuilder->addSortOrder($sortOrder);
}
$this->searchCriteriaBuilder->setCurrentPage($this->_curPage);
$this->searchCriteriaBuilder->setPageSize($this->_pageSize);
return $this->searchCriteriaBuilder->create();
}
示例2: testGetListSortOrder
/**
* @param string $field
* @param string, $direction
* @param string, $methodName
* @param array $expectedResult
*
* @dataProvider sortOrderDataProvider
*/
public function testGetListSortOrder($field, $direction, $methodName, $expectedResult)
{
/** @var \Magento\Framework\Api\SortOrder $sortOrder */
/** @var string $direction */
$direction = $direction == 'ASC' ? SearchCriteria::SORT_ASC : SearchCriteria::SORT_DESC;
$sortOrder = $this->sortOrderBuilder->setField($field)->setDirection($direction)->create();
$this->searchCriteriaBuilder->addSortOrder($sortOrder);
$searchResults = $this->groupRepository->getList($this->searchCriteriaBuilder->create());
/** @var \Magento\Customer\Api\Data\GroupInterface[] $resultItems */
$resultItems = $searchResults->getItems();
$this->assertTrue(count($resultItems) > 0);
$result = [];
foreach ($resultItems as $item) {
/** @var \Magento\Customer\Model\Data\Group $item */
$result[] = $item->{$methodName}();
}
$this->assertEquals($expectedResult, $result);
}