Magento2: Magento\Sales\Model\OrderRepository::getList() is incomplete

Created on 17 Jan 2016  路  13Comments  路  Source: magento/magento2

The implementation of the getList function seems to be missing code to deal with sort orders.

public function getList(\Magento\Framework\Api\SearchCriteria $searchCriteria)
{
    //@TODO: fix search logic
    /** @var \Magento\Sales\Api\Data\OrderSearchResultInterface $searchResult */
    $searchResult = $this->searchResultFactory->create();
    foreach ($searchCriteria->getFilterGroups() as $filterGroup) {
        foreach ($filterGroup->getFilters() as $filter) {
            $condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
            $searchResult->addFieldToFilter($filter->getField(), [$condition => $filter->getValue()]);
        }
    }
    $searchResult->setCurPage($searchCriteria->getCurrentPage());
    $searchResult->setPageSize($searchCriteria->getPageSize());
    return $searchResult;
}

vs this from the getList method in the customer repository class

    $sortOrders = $searchCriteria->getSortOrders();
    if ($sortOrders) {
        /** @var SortOrder $sortOrder */
        foreach ($searchCriteria->getSortOrders() as $sortOrder) {
            $collection->addOrder(
                $sortOrder->getField(),
                ($sortOrder->getDirection() == SortOrder::SORT_ASC) ? 'ASC' : 'DESC'
            );
        }
    }

On a side note there also seems to be some inconsistency if a repository class is a resource model (customer module) or a model (like this one or catalog -> product repository)

Ready for Work bug report

Most helpful comment

@iluvcode it's not in the 2.0.7 release but the change is present in 2.1.0-rc1

All 13 comments

Looks like it's not only missing sort order but also as the filter groups aren't properly mapped, does break and/or functionality in combining multiple search criteria with OR conditions as AND.

It would be nice to have one mapping object that is able to do the std. work on transferring the information of the criteria object parameter from the repository interface to standard resource collection models.

Any ETA on this issue to be fixed?
@NadiyaS

Hi @fooman,
thanks for reporting this. Internal issue was created MAGETWO-49212.

Hey @NadiyaS
Any updates on when the fix will be released?

This issue has been resolved and merged to develop. Feel free to let us know if you encounter any other issues.

@mikeweis This is awesome, thank you for the update. QQ: Will this be a part of 2.0.3 release & is there an ETA for the release? Plmk.

@mikeweis Could you please tell which release would this fix be part of?

Is this already released in patch or will come in future release?

@fooman: Can you confirm this fixed?

@ktomk the code in develop looks good to me but haven't yet had a chance to test it as we have rewritten our code to use a collection for now

@fooman , @ktomk
any luck with Sort functionality? I installed 2.0.5 and it is still broken. I get unsorted results.

rest query: orders?searchCriteria[sortOrders][0][field]=created_at&searchCriteria[sortOrders][0][direction]=desc&searchCriteria[current_page]=1&searchCriteria[page_size]=4

@iluvcode it's not in the 2.0.7 release but the change is present in 2.1.0-rc1

The issue has been included into 2.0.8 release

Was this page helpful?
0 / 5 - 0 ratings