Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function loadData($printQuery = false, $logQuery = false)
 {
     if (!$this->isLoaded()) {
         $searchCriteria = $this->getSearchCriteria();
         $searchResults = $this->accountService->searchCustomers($searchCriteria);
         $this->_totalRecords = $searchResults->getTotalCount();
         /** @var CustomerDetails[] $customers */
         $customers = $searchResults->getItems();
         foreach ($customers as $customer) {
             $this->_addItem($this->createCustomerDetailItem($customer));
         }
         $this->_setIsLoaded();
     }
     return $this;
 }
 /**
  * Test ordering
  *
  * @magentoDataFixture Magento/Customer/_files/three_customers.php
  * @magentoDbIsolation enabled
  */
 public function testSearchCustomersOrder()
 {
     /** @var \Magento\Framework\Service\V1\Data\SearchCriteriaBuilder $searchBuilder */
     $searchBuilder = Bootstrap::getObjectManager()->create('Magento\\Framework\\Service\\V1\\Data\\SearchCriteriaBuilder');
     // Filter for 'firstname' like 'First'
     $filterBuilder = $this->_objectManager->create('\\Magento\\Framework\\Service\\V1\\Data\\FilterBuilder');
     $firstnameFilter = $filterBuilder->setField('firstname')->setConditionType('like')->setValue('First%')->create();
     $searchBuilder->addFilter([$firstnameFilter]);
     // Search ascending order
     $sortOrderBuilder = $this->_objectManager->create('\\Magento\\Framework\\Service\\V1\\Data\\SortOrderBuilder');
     $sortOrder = $sortOrderBuilder->setField('lastname')->setDirection(SearchCriteria::SORT_ASC)->create();
     $searchBuilder->addSortOrder($sortOrder);
     $searchResults = $this->_customerAccountService->searchCustomers($searchBuilder->create());
     $this->assertEquals(3, $searchResults->getTotalCount());
     $this->assertEquals('Lastname', $searchResults->getItems()[0]->getCustomer()->getLastname());
     $this->assertEquals('Lastname2', $searchResults->getItems()[1]->getCustomer()->getLastname());
     $this->assertEquals('Lastname3', $searchResults->getItems()[2]->getCustomer()->getLastname());
     // Search descending order
     $sortOrder = $sortOrderBuilder->setField('lastname')->setDirection(SearchCriteria::SORT_DESC)->create();
     $searchBuilder->addSortOrder($sortOrder);
     $searchResults = $this->_customerAccountService->searchCustomers($searchBuilder->create());
     $this->assertEquals('Lastname3', $searchResults->getItems()[0]->getCustomer()->getLastname());
     $this->assertEquals('Lastname2', $searchResults->getItems()[1]->getCustomer()->getLastname());
     $this->assertEquals('Lastname', $searchResults->getItems()[2]->getCustomer()->getLastname());
 }