当前位置: 首页>>代码示例>>PHP>>正文


PHP Api\SearchCriteriaBuilder类代码示例

本文整理汇总了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]);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:10,代码来源:TierPriceTest.php

示例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)]);
     }, []);
 }
开发者ID:nhp,项目名称:MageTitans_ProductStatus,代码行数:13,代码来源:ProductStatusAdapter.php

示例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);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:10,代码来源:Customer.php

示例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;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:37,代码来源:Customer.php

示例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));
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:25,代码来源:BookmarkManagementTest.php

示例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());
     }
 }
开发者ID:opexsw,项目名称:magento2,代码行数:36,代码来源:CustomerTest.php

示例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));
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:27,代码来源:AggregationResolverTest.php

示例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);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:10,代码来源:AbstractPrice.php

示例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);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:11,代码来源:ServiceSource.php

示例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;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:14,代码来源:Source.php

示例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;
 }
开发者ID:stepzerosolutions,项目名称:tbslider,代码行数:14,代码来源:Source.php

示例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)]);
     }, []);
 }
开发者ID:Vinai,项目名称:MM15PL_ProductStatus,代码行数:13,代码来源:ProductStatusAdapter.php

示例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());
 }
开发者ID:imbrj,项目名称:magento2-samples,代码行数:10,代码来源:FeedListTest.php

示例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;
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:17,代码来源:AttributeProvider.php

示例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;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:17,代码来源:AggregationResolver.php


注:本文中的Magento\Framework\Api\SearchCriteriaBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。