本文整理汇总了PHP中Magento\Framework\Api\SearchCriteriaBuilder::setCurrentPage方法的典型用法代码示例。如果您正苦于以下问题:PHP SearchCriteriaBuilder::setCurrentPage方法的具体用法?PHP SearchCriteriaBuilder::setCurrentPage怎么用?PHP SearchCriteriaBuilder::setCurrentPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Api\SearchCriteriaBuilder
的用法示例。
在下文中一共展示了SearchCriteriaBuilder::setCurrentPage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* Load search results
*
* @return $this
*/
public function load()
{
$result = [];
if (!$this->hasStart() || !$this->hasLimit() || !$this->hasQuery()) {
$this->setResults($result);
return $this;
}
$this->searchCriteriaBuilder->setCurrentPage($this->getStart());
$this->searchCriteriaBuilder->setPageSize($this->getLimit());
$searchFields = ['firstname', 'lastname', 'company'];
$filters = [];
foreach ($searchFields as $field) {
$filters[] = $this->filterBuilder->setField($field)->setConditionType('like')->setValue($this->getQuery() . '%')->create();
}
$this->searchCriteriaBuilder->addFilters($filters);
$searchCriteria = $this->searchCriteriaBuilder->create();
$searchResults = $this->customerRepository->getList($searchCriteria);
foreach ($searchResults->getItems() as $customer) {
$customerAddresses = $customer->getAddresses();
/** Look for a company name defined in default billing address */
$company = null;
foreach ($customerAddresses as $customerAddress) {
if ($customerAddress->getId() == $customer->getDefaultBilling()) {
$company = $customerAddress->getCompany();
break;
}
}
$result[] = ['id' => 'customer/1/' . $customer->getId(), 'type' => __('Customer'), 'name' => $this->_customerViewHelper->getCustomerName($customer), 'description' => $company, 'url' => $this->_adminhtmlData->getUrl('customer/index/edit', ['id' => $customer->getId()])];
}
$this->setResults($result);
return $this;
}
示例2: testSearchCustomersMultipleFilterGroups
/**
* Test using multiple filters
*/
public function testSearchCustomersMultipleFilterGroups()
{
$customerData1 = $this->_createCustomer();
/** @var \Magento\Framework\Api\FilterBuilder $builder */
$builder = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\FilterBuilder');
$filter1 = $builder->setField(Customer::EMAIL)->setValue($customerData1[Customer::EMAIL])->create();
$filter2 = $builder->setField(Customer::MIDDLENAME)->setValue($customerData1[Customer::MIDDLENAME])->create();
$filter3 = $builder->setField(Customer::MIDDLENAME)->setValue('invalid')->create();
$filter4 = $builder->setField(Customer::LASTNAME)->setValue($customerData1[Customer::LASTNAME])->create();
$this->searchCriteriaBuilder->addFilters([$filter1]);
$this->searchCriteriaBuilder->addFilters([$filter2, $filter3]);
$this->searchCriteriaBuilder->addFilters([$filter4]);
$searchCriteria = $this->searchCriteriaBuilder->setCurrentPage(1)->setPageSize(10)->create();
$searchData = $searchCriteria->__toArray();
$requestData = ['searchCriteria' => $searchData];
$serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . '/search' . '?' . http_build_query($requestData), 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'getList']];
$searchResults = $this->_webApiCall($serviceInfo, $requestData);
$this->assertEquals(1, $searchResults['total_count']);
$this->assertEquals($customerData1[Customer::ID], $searchResults['items'][0][Customer::ID]);
// Add an invalid And-ed data with multiple groups to yield no result
$filter4 = $builder->setField(Customer::LASTNAME)->setValue('invalid')->create();
$this->searchCriteriaBuilder->addFilters([$filter1]);
$this->searchCriteriaBuilder->addFilters([$filter2, $filter3]);
$this->searchCriteriaBuilder->addFilters([$filter4]);
$searchCriteria = $this->searchCriteriaBuilder->create();
$searchData = $searchCriteria->__toArray();
$requestData = ['searchCriteria' => $searchData];
$serviceInfo['rest']['resourcePath'] = self::RESOURCE_PATH . '/search' . '?' . http_build_query($requestData);
$searchResults = $this->_webApiCall($serviceInfo, $requestData);
$this->assertEquals(0, $searchResults['total_count']);
}
示例3: testSearchTaxClassMultipleFilterGroups
/**
* Test using multiple filters
*/
public function testSearchTaxClassMultipleFilterGroups()
{
$productTaxClass = [ClassModel::KEY_NAME => 'Taxable Goods', ClassModel::KEY_TYPE => 'PRODUCT'];
$customerTaxClass = [ClassModel::KEY_NAME => 'Retail Customer', ClassModel::KEY_TYPE => 'CUSTOMER'];
$filter1 = $this->filterBuilder->setField(ClassModel::KEY_NAME)->setValue($productTaxClass[ClassModel::KEY_NAME])->create();
$filter2 = $this->filterBuilder->setField(ClassModel::KEY_NAME)->setValue($customerTaxClass[ClassModel::KEY_NAME])->create();
$filter3 = $this->filterBuilder->setField(ClassModel::KEY_TYPE)->setValue($productTaxClass[ClassModel::KEY_TYPE])->create();
$filter4 = $this->filterBuilder->setField(ClassModel::KEY_TYPE)->setValue($customerTaxClass[ClassModel::KEY_TYPE])->create();
/**
* (class_name == 'Retail Customer' || class_name == 'Taxable Goods)
* && ( class_type == 'CUSTOMER' || class_type == 'PRODUCT')
*/
$this->searchCriteriaBuilder->addFilters([$filter1, $filter2]);
$this->searchCriteriaBuilder->addFilters([$filter3, $filter4]);
$searchCriteria = $this->searchCriteriaBuilder->setCurrentPage(1)->setPageSize(10)->create();
$searchData = $searchCriteria->__toArray();
$requestData = ['searchCriteria' => $searchData];
$serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . '/search' . '?' . http_build_query($requestData), 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'GetList']];
$searchResults = $this->_webApiCall($serviceInfo, $requestData);
$this->assertEquals(2, $searchResults['total_count']);
$this->assertEquals($productTaxClass[ClassModel::KEY_NAME], $searchResults['items'][0][ClassModel::KEY_NAME]);
$this->assertEquals($customerTaxClass[ClassModel::KEY_NAME], $searchResults['items'][1][ClassModel::KEY_NAME]);
/** class_name == 'Retail Customer' && ( class_type == 'CUSTOMER' || class_type == 'PRODUCT') */
$this->searchCriteriaBuilder->addFilters([$filter2]);
$this->searchCriteriaBuilder->addFilters([$filter3, $filter4]);
$searchCriteria = $this->searchCriteriaBuilder->create();
$searchData = $searchCriteria->__toArray();
$requestData = ['searchCriteria' => $searchData];
$serviceInfo['rest']['resourcePath'] = self::RESOURCE_PATH . '/search' . '?' . http_build_query($requestData);
$searchResults = $this->_webApiCall($serviceInfo, $requestData);
$this->assertEquals(1, $searchResults['total_count']);
$this->assertEquals($customerTaxClass[ClassModel::KEY_NAME], $searchResults['items'][0][ClassModel::KEY_NAME]);
}
示例4: 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();
}
示例5: testGetSearchCriteriaAnd
public function testGetSearchCriteriaAnd()
{
// Test ((A > 1) and (B > 1))
$fieldA = 'A';
$fieldB = 'B';
$value = 1;
$sortOrder = $this->sortOrderBuilder->setField('name')->setDirection(SortOrder::SORT_ASC)->create();
/** @var SearchCriteria $expectedSearchCriteria */
$expectedSearchCriteria = $this->searchCriteriaBuilder->setCurrentPage(1)->setPageSize(0)->addSortOrder($sortOrder)->addFilters([$this->filterBuilder->setField($fieldA)->setConditionType('gt')->setValue($value)->create()])->addFilters([$this->filterBuilder->setField($fieldB)->setConditionType('gt')->setValue($value)->create()])->create();
// Verifies that the search criteria Data Object created by the serviceCollection matches expected
$this->groupRepositoryMock->expects($this->once())->method('getList')->with($this->equalTo($expectedSearchCriteria))->will($this->returnValue($this->searchResults));
// Now call service collection to load the data. This causes it to create the search criteria Data Object
$this->serviceCollection->addFieldToFilter($fieldA, ['gt' => $value]);
$this->serviceCollection->addFieldToFilter($fieldB, ['gt' => $value]);
$this->serviceCollection->setOrder('name', ServiceCollection::SORT_ORDER_ASC);
$this->serviceCollection->loadData();
}
示例6: getList
/**
* {@inheritdoc}
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
{
$this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField('entity_type_code')->setValue(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE)->setConditionType('eq')->create()]);
$this->searchCriteriaBuilder->setCurrentPage($searchCriteria->getCurrentPage());
$this->searchCriteriaBuilder->setPageSize($searchCriteria->getPageSize());
return $this->attributeSetRepository->getList($this->searchCriteriaBuilder->create());
}