本文整理汇总了PHP中Magento\Framework\Api\SearchCriteriaBuilder类的典型用法代码示例。如果您正苦于以下问题:PHP SearchCriteriaBuilder类的具体用法?PHP SearchCriteriaBuilder怎么用?PHP SearchCriteriaBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SearchCriteriaBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
$this->groupRepositoryInterface = $this->getMock('Magento\\Customer\\Model\\ResourceModel\\GroupRepository', [], [], '', false);
$this->searchCriteriaSearch = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false);
$this->searchCriteriaBuilder = $this->getMock('Magento\\Framework\\Api\\SearchCriteriaBuilder', [], [], '', false);
$this->searchCriteriaBuilder->expects($this->any())->method('create')->willReturn($this->searchCriteriaSearch);
$this->storeResolver = $this->getMock('Magento\\CatalogImportExport\\Model\\Import\\Product\\StoreResolver', [], [], '', false);
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->tierPrice = $this->objectManagerHelper->getObject('Magento\\CatalogImportExport\\Model\\Import\\Product\\Validator\\TierPrice', ['groupRepository' => $this->groupRepositoryInterface, 'searchCriteriaBuilder' => $this->searchCriteriaBuilder, 'storeResolver' => $this->storeResolver]);
}
示例2: getProductStatusMatchingSku
/**
* @param string $sku
* @return string[]
*/
public function getProductStatusMatchingSku($sku)
{
$this->validateSku($sku);
$this->searchCriteriaBuilder->addFilter('sku', '%' . $sku . '%', 'like');
$result = $this->productRepository->getList($this->searchCriteriaBuilder->create());
return array_reduce($result->getItems(), function ($acc, ProductInterface $product) {
return array_merge($acc, [$product->getSku() => $this->getStatusAsString($product)]);
}, []);
}
示例3: isAssignedToObjects
/**
* {@inheritdoc}
*/
public function isAssignedToObjects()
{
$searchCriteria = $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField(CustomerGroup::TAX_CLASS_ID)->setValue($this->getId())->create()])->create();
$result = $this->customerGroupRepository->getList($searchCriteria);
$items = $result->getItems();
return !empty($items);
}
示例4: 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;
}
示例5: testGetByIdentifierNamespace
public function testGetByIdentifierNamespace()
{
$userId = 1;
$namespace = 'some_namespace';
$identifier = 'current';
$this->userContext->expects($this->once())->method('getUserId')->willReturn($userId);
$fieldUserId = new Filter([Filter::KEY_FIELD => 'user_id', Filter::KEY_VALUE => $userId, Filter::KEY_CONDITION_TYPE => 'eq']);
$fieldIdentifier = new Filter([Filter::KEY_FIELD => 'identifier', Filter::KEY_VALUE => $identifier, Filter::KEY_CONDITION_TYPE => 'eq']);
$fieldNamespace = new Filter([Filter::KEY_FIELD => 'namespace', Filter::KEY_VALUE => $namespace, Filter::KEY_CONDITION_TYPE => 'eq']);
$bookmarkId = 1;
$bookmark = $this->getMockBuilder('Magento\\Ui\\Api\\Data\\BookmarkInterface')->getMockForAbstractClass();
$bookmark->expects($this->once())->method('getId')->willReturn($bookmarkId);
$searchCriteria = $this->getMockBuilder('Magento\\Framework\\Api\\SearchCriteriaInterface')->getMockForAbstractClass();
$this->filterBuilder->expects($this->at(0))->method('create')->willReturn($fieldUserId);
$this->filterBuilder->expects($this->at(1))->method('create')->willReturn($fieldIdentifier);
$this->filterBuilder->expects($this->at(2))->method('create')->willReturn($fieldNamespace);
$this->searchCriteriaBuilder->expects($this->once())->method('addFilters')->with([$fieldUserId, $fieldIdentifier, $fieldNamespace]);
$this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria);
$searchResult = $this->getMockBuilder('Magento\\Ui\\Api\\Data\\BookmarkSearchResultsInterface')->getMockForAbstractClass();
$searchResult->expects($this->once())->method('getTotalCount')->willReturn(1);
$searchResult->expects($this->once())->method('getItems')->willReturn([$bookmark]);
$this->bookmarkRepository->expects($this->once())->method('getList')->with($searchCriteria)->willReturn($searchResult);
$this->bookmarkRepository->expects($this->once())->method('getById')->with($bookmarkId)->willReturn($bookmark);
$this->assertEquals($bookmark, $this->bookmarkManagement->getByIdentifierNamespace($identifier, $namespace));
}
示例6: testGetAllOptions
/**
* Run test getAllOptions method
*
* @param bool $isEmpty
* @param array $expected
* @dataProvider dataProviderGetAllOptions
*/
public function testGetAllOptions($isEmpty, array $expected)
{
$filterMock = $this->getMock('Magento\\Framework\\Api\\Filter', [], [], '', false);
$searchCriteriaMock = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false);
$searchResultsMock = $this->getMockForAbstractClass('Magento\\Tax\\Api\\Data\\TaxClassSearchResultsInterface', [], '', false, true, true, ['getItems']);
$taxClassMock = $this->getMockForAbstractClass('Magento\\Tax\\Api\\Data\\TaxClassInterface', ['getClassId', 'getClassName'], '', false, true, true);
$this->filterBuilderMock->expects($this->once())->method('setField')->with(\Magento\Tax\Model\ClassModel::KEY_TYPE)->willReturnSelf();
$this->filterBuilderMock->expects($this->once())->method('setValue')->with(\Magento\Tax\Api\TaxClassManagementInterface::TYPE_CUSTOMER)->willReturnSelf();
$this->filterBuilderMock->expects($this->once())->method('create')->willReturn($filterMock);
$this->searchCriteriaBuilderMock->expects($this->once())->method('addFilter')->with([$filterMock])->willReturnSelf();
$this->searchCriteriaBuilderMock->expects($this->once())->method('create')->willReturn($searchCriteriaMock);
$this->taxClassRepositoryMock->expects($this->once())->method('getList')->with($searchCriteriaMock)->willReturn($searchResultsMock);
if (!$isEmpty) {
$taxClassMock->expects($this->once())->method('getClassId')->willReturn(10);
$taxClassMock->expects($this->once())->method('getClassName')->willReturn('class-name');
$items = [$taxClassMock];
$searchResultsMock->expects($this->once())->method('getItems')->willReturn($items);
// checking of a lack of re-initialization
for ($i = 10; --$i;) {
$result = $this->customer->getAllOptions();
$this->assertEquals($expected, $result);
}
} else {
$items = [];
$searchResultsMock->expects($this->once())->method('getItems')->willReturn($items);
// checking exception
$this->assertEmpty($this->customer->getAllOptions());
}
}
示例7: testResolve
public function testResolve()
{
$documentIds = [1, 2, 3];
$attributeSetIds = [4, 5];
$requestName = 'request_name';
$this->attributeSetFinder->expects($this->once())->method('findAttributeSetIdsByProductIds')->with($documentIds)->willReturn($attributeSetIds);
$searchCriteria = $this->getMock(SearchCriteriaInterface::class);
$this->searchCriteriaBuilder->expects($this->once())->method('addFilter')->with('attribute_set_id', $attributeSetIds, 'in')->willReturnSelf();
$this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria);
$attributeFirst = $this->getMock(ProductAttributeInterface::class);
$attributeFirst->expects($this->once())->method('getAttributeCode')->willReturn('code_1');
$attributeSecond = $this->getMock(ProductAttributeInterface::class);
$attributeSecond->expects($this->once())->method('getAttributeCode')->willReturn('code_2');
$searchResult = $this->getMock(ProductAttributeSearchResultsInterface::class);
$searchResult->expects($this->once())->method('getItems')->willReturn([$attributeFirst, $attributeSecond]);
$this->productAttributeRepository->expects($this->once())->method('getList')->with($searchCriteria)->willReturn($searchResult);
$bucketFirst = $this->getMock(BucketInterface::class);
$bucketFirst->expects($this->once())->method('getField')->willReturn('code_1');
$bucketSecond = $this->getMock(BucketInterface::class);
$bucketSecond->expects($this->once())->method('getField')->willReturn('some_another_code');
$bucketThird = $this->getMock(BucketInterface::class);
$bucketThird->expects($this->once())->method('getName')->willReturn('custom_not_attribute_field');
$this->request->expects($this->once())->method('getAggregation')->willReturn([$bucketFirst, $bucketSecond, $bucketThird]);
$this->request->expects($this->once())->method('getName')->willReturn($requestName);
$this->config->expects($this->once())->method('get')->with($requestName)->willReturn(['aggregations' => ['custom_not_attribute_field' => []]]);
$this->assertEquals([$bucketFirst, $bucketThird], $this->aggregationResolver->resolve($this->request, $documentIds));
}
示例8: init
/**
* {@inheritdoc}
*/
public function init($context)
{
foreach ($this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems() as $group) {
$this->customerGroups[$group->getId()] = true;
}
return parent::init($context);
}
示例9: getData
/**
* {@inheritdoc}
*/
public function getData(array $fieldsData)
{
$service = $this->getService();
$searchCriteria = $this->searchCriteriaBuilder->create();
/** @var SearchResults $list */
$list = $service->getList($searchCriteria);
return $this->getRequestedFields($list, $fieldsData);
}
示例10: toOptionArray
/**
* Retrieve all tax rates as an options array.
*
* @return array
*/
public function toOptionArray()
{
if (!$this->options) {
$searchCriteria = $this->searchCriteriaBuilder->create();
$searchResults = $this->taxRateRepository->getList($searchCriteria);
$this->options = $this->converter->toOptionArray($searchResults->getItems(), Rate::KEY_ID, Rate::KEY_CODE);
}
return $this->options;
}
示例11: toOptionArray
/**
* Retrieve all tax rates as an options array.
*
* @return array
*/
public function toOptionArray()
{
if (!$this->options) {
$searchCriteria = $this->searchCriteriaBuilder->create();
$searchResults = $this->sliderRepository->getList($searchCriteria);
$this->options = $this->converter->toOptionArray($searchResults->getItems(), Slider::ID, Slider::SLIDER_TITLE);
}
return $this->options;
}
示例12: getStatusForProductsMatchingSku
/**
* @param string $sku
* @return string[]
*/
public function getStatusForProductsMatchingSku($sku)
{
$this->validateSku($sku);
$this->searchCriteriaBuilder->addFilter('sku', $this->getLikeSkuExpression($sku), 'like');
$productList = $this->productRepository->getList($this->searchCriteriaBuilder->create());
return array_reduce($productList->getItems(), function (array $carry, ProductInterface $product) {
return array_merge($carry, [$product->getSku() => $this->getStatusString($product)]);
}, []);
}
示例13: testGetFeeds
public function testGetFeeds()
{
$feeds = ['feed1', 'feed2'];
$searchCriteria = $this->getMockBuilder('\\Magento\\Framework\\Api\\SearchCriteria')->disableOriginalConstructor()->getMock();
$this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria);
$searchResult = $this->getMockBuilder('\\Magento\\SampleServiceContractNew\\API\\Data\\FeedSearchResultInterface')->disableOriginalConstructor()->getMockForAbstractClass();
$searchResult->expects($this->once())->method('getItems')->willReturn($feeds);
$this->feedRepository->expects($this->once())->method('getList')->willReturn($searchResult);
$this->assertEquals($feeds, $this->block->getFeeds());
}
示例14: getAttributes
/**
* Returns array of fields
*
* @param string $entityType
* @return array
* @throws \Exception
*/
public function getAttributes($entityType)
{
$metadata = $this->metadataPool->getMetadata($entityType);
$searchResult = $this->attributeRepository->getList($metadata->getEavEntityType(), $this->searchCriteriaBuilder->create());
$attributes = [];
foreach ($searchResult->getItems() as $attribute) {
$attributes[] = $attribute->getAttributeCode();
}
return $attributes;
}
示例15: getApplicableAttributeCodes
/**
* Get applicable attributes
*
* @param array $documentIds
* @return array
*/
private function getApplicableAttributeCodes(array $documentIds)
{
$attributeSetIds = $this->attributeSetFinder->findAttributeSetIdsByProductIds($documentIds);
$searchCriteria = $this->searchCriteriaBuilder->addFilter('attribute_set_id', $attributeSetIds, 'in')->create();
$result = $this->productAttributeRepository->getList($searchCriteria);
$attributeCodes = [];
foreach ($result->getItems() as $attribute) {
$attributeCodes[] = $attribute->getAttributeCode();
}
return $attributeCodes;
}