/**
  * {@inheritdoc}
  */
 public function getList(\Magento\Framework\Api\SearchCriteria $searchCriteria)
 {
     $quoteCollection = $this->quoteCollectionFactory->create();
     $this->extensionAttributesJoinProcessor->process($quoteCollection);
     $searchData = $this->searchResultsDataFactory->create();
     $searchData->setSearchCriteria($searchCriteria);
     $searchData->setItems($quoteCollection->getItems());
     return $searchData;
 }
 /**
  * {@inheritdoc}
  */
 public function getList(\Magento\Framework\Api\SearchCriteria $searchCriteria)
 {
     $this->quoteCollection = $this->getQuoteCollection();
     /** @var \Magento\Quote\Api\Data\CartSearchResultsInterface $searchData */
     $searchData = $this->searchResultsDataFactory->create();
     $searchData->setSearchCriteria($searchCriteria);
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $this->quoteCollection);
     }
     $searchData->setTotalCount($this->quoteCollection->getSize());
     $sortOrders = $searchCriteria->getSortOrders();
     if ($sortOrders) {
         /** @var SortOrder $sortOrder */
         foreach ($sortOrders as $sortOrder) {
             $this->quoteCollection->addOrder($sortOrder->getField(), $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $this->quoteCollection->setCurPage($searchCriteria->getCurrentPage());
     $this->quoteCollection->setPageSize($searchCriteria->getPageSize());
     $this->extensionAttributesJoinProcessor->process($this->quoteCollection);
     foreach ($this->quoteCollection->getItems() as $quote) {
         /** @var CartInterface $quote */
         $this->getLoadHandler()->load($quote);
     }
     $searchData->setItems($this->quoteCollection->getItems());
     return $searchData;
 }
 /**
  * @param int $direction
  * @param string $expectedDirection
  * @dataProvider getListSuccessDataProvider
  */
 public function testGetListSuccess($direction, $expectedDirection)
 {
     $searchResult = $this->getMock('\\Magento\\Quote\\Api\\Data\\CartSearchResultsInterface', [], [], '', false);
     $searchCriteriaMock = $this->getMock('\\Magento\\Framework\\Api\\SearchCriteria', [], [], '', false);
     $cartMock = $this->getMock('Magento\\Payment\\Model\\Cart', [], [], '', false);
     $filterMock = $this->getMock('\\Magento\\Framework\\Api\\Filter', [], [], '', false);
     $pageSize = 10;
     $this->searchResultsDataFactory->expects($this->once())->method('create')->will($this->returnValue($searchResult));
     $searchResult->expects($this->once())->method('setSearchCriteria');
     $filterGroupMock = $this->getMock('\\Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false);
     $searchCriteriaMock->expects($this->any())->method('getFilterGroups')->will($this->returnValue([$filterGroupMock]));
     //addFilterGroupToCollection() checks
     $filterGroupMock->expects($this->any())->method('getFilters')->will($this->returnValue([$filterMock]));
     $filterMock->expects($this->once())->method('getField')->will($this->returnValue('store_id'));
     $filterMock->expects($this->any())->method('getConditionType')->will($this->returnValue('eq'));
     $filterMock->expects($this->once())->method('getValue')->will($this->returnValue('filter_value'));
     //back in getList()
     $this->quoteCollectionMock->expects($this->once())->method('getSize')->willReturn($pageSize);
     $searchResult->expects($this->once())->method('setTotalCount')->with($pageSize);
     $sortOrderMock = $this->getMockBuilder('Magento\\Framework\\Api\\SortOrder')->setMethods(['getField', 'getDirection'])->disableOriginalConstructor()->getMock();
     //foreach cycle
     $searchCriteriaMock->expects($this->once())->method('getSortOrders')->will($this->returnValue([$sortOrderMock]));
     $sortOrderMock->expects($this->once())->method('getField')->will($this->returnValue('id'));
     $sortOrderMock->expects($this->once())->method('getDirection')->will($this->returnValue($direction));
     $this->quoteCollectionMock->expects($this->once())->method('addOrder')->with('id', $expectedDirection);
     $searchCriteriaMock->expects($this->once())->method('getCurrentPage')->will($this->returnValue(1));
     $searchCriteriaMock->expects($this->once())->method('getPageSize')->will($this->returnValue(10));
     $this->quoteCollectionMock->expects($this->once())->method('setCurPage')->with(1);
     $this->quoteCollectionMock->expects($this->once())->method('setPageSize')->with(10);
     $this->extensionAttributesJoinProcessorMock->expects($this->once())->method('process')->with($this->isInstanceOf('\\Magento\\Quote\\Model\\ResourceModel\\Quote\\Collection'));
     $this->quoteCollectionMock->expects($this->once())->method('getItems')->willReturn([$cartMock]);
     $searchResult->expects($this->once())->method('setItems')->with([$cartMock]);
     $this->assertEquals($searchResult, $this->model->getList($searchCriteriaMock));
 }
 /**
  * {@inheritdoc}
  */
 public function getList(\Magento\Framework\Api\SearchCriteria $searchCriteria)
 {
     $searchData = $this->searchResultsDataFactory->create();
     $searchData->setSearchCriteria($searchCriteria);
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $this->quoteCollection);
     }
     $searchData->setTotalCount($this->quoteCollection->getSize());
     $sortOrders = $searchCriteria->getSortOrders();
     if ($sortOrders) {
         foreach ($sortOrders as $sortOrder) {
             $this->quoteCollection->addOrder($sortOrder->getField(), $sortOrder->getDirection() == SearchCriteria::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $this->quoteCollection->setCurPage($searchCriteria->getCurrentPage());
     $this->quoteCollection->setPageSize($searchCriteria->getPageSize());
     $searchData->setItems($this->quoteCollection->getItems());
     return $searchData;
 }