本文整理汇总了PHP中Magento\Framework\Api\SearchCriteriaBuilder::setSortOrders方法的典型用法代码示例。如果您正苦于以下问题:PHP SearchCriteriaBuilder::setSortOrders方法的具体用法?PHP SearchCriteriaBuilder::setSortOrders怎么用?PHP SearchCriteriaBuilder::setSortOrders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Api\SearchCriteriaBuilder
的用法示例。
在下文中一共展示了SearchCriteriaBuilder::setSortOrders方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetList
/**
* @magentoApiDataFixture Magento/Sales/_files/quote.php
*/
public function testGetList()
{
$cart = $this->getCart('test01');
// The following two filters are used as alternatives. The target cart does not match the first one.
$grandTotalFilter = $this->filterBuilder->setField('grand_total')->setConditionType('gteq')->setValue(15)->create();
$subtotalFilter = $this->filterBuilder->setField('subtotal')->setConditionType('eq')->setValue($cart->getSubtotal())->create();
$yesterdayDate = (new \DateTime($cart->getCreatedAt()))->sub(new \DateInterval('P1D'))->format('Y-m-d');
$tomorrowDate = (new \DateTime($cart->getCreatedAt()))->add(new \DateInterval('P1D'))->format('Y-m-d');
$minCreatedAtFilter = $this->filterBuilder->setField('created_at')->setConditionType('gteq')->setValue($yesterdayDate)->create();
$maxCreatedAtFilter = $this->filterBuilder->setField('created_at')->setConditionType('lteq')->setValue($tomorrowDate)->create();
$this->searchCriteriaBuilder->addFilters([$grandTotalFilter, $subtotalFilter]);
$this->searchCriteriaBuilder->addFilters([$minCreatedAtFilter]);
$this->searchCriteriaBuilder->addFilters([$maxCreatedAtFilter]);
/** @var SortOrder $sortOrder */
$sortOrder = $this->sortOrderBuilder->setField('subtotal')->setDirection(SortOrder::SORT_ASC)->create();
$this->searchCriteriaBuilder->setSortOrders([$sortOrder]);
$searchCriteria = $this->searchCriteriaBuilder->create()->__toArray();
$requestData = ['searchCriteria' => $searchCriteria];
$serviceInfo = ['rest' => ['resourcePath' => '/V1/carts/search' . '?' . http_build_query($requestData), 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET], 'soap' => ['service' => 'quoteCartRepositoryV1', 'serviceVersion' => 'V1', 'operation' => 'quoteCartRepositoryV1GetList']];
$searchResult = $this->_webApiCall($serviceInfo, $requestData);
$this->assertArrayHasKey('total_count', $searchResult);
$this->assertEquals(1, $searchResult['total_count']);
$this->assertArrayHasKey('items', $searchResult);
$this->assertCount(1, $searchResult['items']);
$cartData = $searchResult['items'][0];
$this->assertEquals($cart->getId(), $cartData['id']);
$this->assertEquals($cart->getCreatedAt(), $cartData['created_at']);
$this->assertEquals($cart->getUpdatedAt(), $cartData['updated_at']);
$this->assertEquals($cart->getIsActive(), $cartData['is_active']);
$this->assertContains('customer_is_guest', $cartData);
$this->assertEquals(1, $cartData['customer_is_guest']);
}
示例2: testAutoGeneratedGetList
/**
* @magentoApiDataFixture Magento/Sales/_files/invoice.php
*/
public function testAutoGeneratedGetList()
{
$this->getExpectedExtensionAttributes();
/** @var SortOrder $sortOrder */
$sortOrder = $this->sortOrderBuilder->setField('store_id')->setDirection(SearchCriteria::SORT_ASC)->create();
$this->searchBuilder->setSortOrders([$sortOrder]);
$this->searchBuilder->addFilters([$this->filterBuilder->setField('state')->setValue(2)->create()]);
$searchCriteria = $this->searchBuilder->create()->__toArray();
$requestData = ['criteria' => $searchCriteria];
$restResourcePath = '/V1/invoices/';
$soapService = 'salesInvoiceRepositoryV1';
$expectedExtensionAttributes = $this->getExpectedExtensionAttributes();
$serviceInfo = ['rest' => ['resourcePath' => $restResourcePath . '?' . http_build_query($requestData), 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET], 'soap' => ['service' => $soapService, 'operation' => $soapService . 'GetList']];
$searchResult = $this->_webApiCall($serviceInfo, $requestData);
$this->assertArrayHasKey('items', $searchResult);
$itemData = array_pop($searchResult['items']);
$this->assertArrayHasKey('extension_attributes', $itemData);
$this->assertArrayHasKey('invoice_api_test_attribute', $itemData['extension_attributes']);
$testAttribute = $itemData['extension_attributes']['invoice_api_test_attribute'];
$this->assertEquals($expectedExtensionAttributes['firstname'], $testAttribute['first_name']);
$this->assertEquals($expectedExtensionAttributes['lastname'], $testAttribute['last_name']);
$this->assertEquals($expectedExtensionAttributes['email'], $testAttribute['email']);
}
示例3: testSearchCustomersMultipleFiltersWithSortUsingGET
/**
* Test using multiple filters using GET
*/
public function testSearchCustomersMultipleFiltersWithSortUsingGET()
{
$this->_markTestAsRestOnly('SOAP test is covered in testSearchCustomers');
$builder = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\FilterBuilder');
$customerData1 = $this->_createCustomer();
$customerData2 = $this->_createCustomer();
$filter1 = $builder->setField(Customer::EMAIL)->setValue($customerData1[Customer::EMAIL])->create();
$filter2 = $builder->setField(Customer::EMAIL)->setValue($customerData2[Customer::EMAIL])->create();
$filter3 = $builder->setField(Customer::LASTNAME)->setValue($customerData1[Customer::LASTNAME])->create();
$this->searchCriteriaBuilder->addFilters([$filter1, $filter2]);
$this->searchCriteriaBuilder->addFilters([$filter3]);
$this->searchCriteriaBuilder->setSortOrders([Customer::EMAIL => SortOrder::SORT_ASC]);
$searchCriteria = $this->searchCriteriaBuilder->create();
$searchData = $searchCriteria->__toArray();
$requestData = ['searchCriteria' => $searchData];
$searchQueryString = http_build_query($requestData);
$serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . '/search?' . $searchQueryString, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET]];
$searchResults = $this->_webApiCall($serviceInfo);
$this->assertEquals(2, $searchResults['total_count']);
$this->assertEquals($customerData1[Customer::ID], $searchResults['items'][0][Customer::ID]);
$this->assertEquals($customerData2[Customer::ID], $searchResults['items'][1][Customer::ID]);
}