本文整理汇总了PHP中Magento\Framework\Api\SearchCriteriaBuilder类的典型用法代码示例。如果您正苦于以下问题:PHP SearchCriteriaBuilder类的具体用法?PHP SearchCriteriaBuilder怎么用?PHP SearchCriteriaBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SearchCriteriaBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: setUp
protected function setUp()
{
$this->contextMock = $this->getMockBuilder(ContextInterface::class)->getMockForAbstractClass();
$this->attributeRepositoryMock = $this->getMockBuilder(ProductAttributeRepositoryInterface::class)->getMockForAbstractClass();
$this->searchCriteriaBuilderMock = $this->getMockBuilder(SearchCriteriaBuilder::class)->disableOriginalConstructor()->getMock();
$this->uiElementProcessorMock = $this->getMockBuilder(UiElementProcessor::class)->disableOriginalConstructor()->getMock();
$this->searchCriteriaMock = $this->getMockBuilder(SearchCriteria::class)->disableOriginalConstructor()->getMock();
$this->searchResultsMock = $this->getMockBuilder(ProductAttributeSearchResultsInterface::class)->getMockForAbstractClass();
$this->contextMock->expects(static::any())->method('getProcessor')->willReturn($this->uiElementProcessorMock);
$this->searchCriteriaBuilderMock->expects(static::any())->method('addFilter')->willReturnSelf();
$this->searchCriteriaBuilderMock->expects(static::any())->method('create')->willReturn($this->searchCriteriaMock);
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->attributesColumn = $this->objectManagerHelper->getObject(AttributesColumn::class, ['context' => $this->contextMock, 'attributeRepository' => $this->attributeRepositoryMock, 'searchCriteriaBuilder' => $this->searchCriteriaBuilderMock]);
}
开发者ID:Doability,项目名称:magento2dev,代码行数:14,代码来源:AttributesTest.php
示例3: 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
示例4: 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
示例5: 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
示例6: 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
示例7: 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
示例8: 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
示例9: 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
示例10: 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
示例11: 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
示例12: 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
示例13: 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
示例14: 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
示例15: 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
示例16: 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
示例17: getMetadataValues
/**
* Get metadata for sales rule form. It will be merged with form UI component declaration.
*
* @param Rule $rule
* @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function getMetadataValues(\Magento\SalesRule\Model\Rule $rule)
{
$customerGroups = $this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems();
$applyOptions = [['label' => __('Percent of product price discount'), 'value' => Rule::BY_PERCENT_ACTION], ['label' => __('Fixed amount discount'), 'value' => Rule::BY_FIXED_ACTION], ['label' => __('Fixed amount discount for whole cart'), 'value' => Rule::CART_FIXED_ACTION], ['label' => __('Buy X get Y free (discount amount is Y)'), 'value' => Rule::BUY_X_GET_Y_ACTION]];
$couponTypesOptions = [];
$couponTypes = $this->salesRuleFactory->create()->getCouponTypes();
foreach ($couponTypes as $key => $couponType) {
$couponTypesOptions[] = ['label' => $couponType, 'value' => $key];
}
$labels = $rule->getStoreLabels();
return ['rule_information' => ['children' => ['website_ids' => ['arguments' => ['data' => ['config' => ['options' => $this->store->getWebsiteValuesForForm()]]]], 'is_active' => ['arguments' => ['data' => ['config' => ['options' => [['label' => __('Active'), 'value' => '1'], ['label' => __('Inactive'), 'value' => '0']]]]]], 'customer_group_ids' => ['arguments' => ['data' => ['config' => ['options' => $this->objectConverter->toOptionArray($customerGroups, 'id', 'code')]]]], 'coupon_type' => ['arguments' => ['data' => ['config' => ['options' => $couponTypesOptions]]]], 'is_rss' => ['arguments' => ['data' => ['config' => ['options' => [['label' => __('Yes'), 'value' => '1'], ['label' => __('No'), 'value' => '0']]]]]]]], 'actions' => ['children' => ['simple_action' => ['arguments' => ['data' => ['config' => ['options' => $applyOptions]]]], 'discount_amount' => ['arguments' => ['data' => ['config' => ['value' => '0']]]], 'discount_qty' => ['arguments' => ['data' => ['config' => ['value' => '0']]]], 'apply_to_shipping' => ['arguments' => ['data' => ['config' => ['options' => [['label' => __('Yes'), 'value' => '1'], ['label' => __('No'), 'value' => '0']]]]]], 'stop_rules_processing' => ['arguments' => ['data' => ['config' => ['options' => [['label' => __('Yes'), 'value' => '1'], ['label' => __('No'), 'value' => '0']]]]]]]], 'labels' => ['children' => ['store_labels[0]' => ['arguments' => ['data' => ['config' => ['value' => isset($labels[0]) ? $labels[0] : '']]]]]]];
}
开发者ID:Doability,项目名称:magento2dev,代码行数:19,代码来源:ValueProvider.php
示例18: execute
/**
* @return void
*/
public function execute()
{
$filter = $this->filterBuilder->setField('parent_id')->setValue($this->_getCheckout()->getCustomer()->getId())->setConditionType('eq')->create();
$addresses = (array) $this->addressRepository->getList($this->searchCriteriaBuilder->addFilters([$filter])->create())->getItems();
/**
* if we create first address we need reset emd init checkout
*/
if (count($addresses) === 1) {
$this->_getCheckout()->reset();
}
$this->_redirect('*/checkout/addresses');
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:ShippingSaved.php
示例19: getAttributes
/**
* @param string $entityType
* @return \Magento\Eav\Api\Data\AttributeInterface[]
* @throws \Exception
*/
protected function getAttributes($entityType)
{
$attributes = $this->attributeCache->getAttributes($entityType);
if ($attributes) {
return $attributes;
}
$metadata = $this->metadataPool->getMetadata($entityType);
$searchResult = $this->attributeRepository->getList($metadata->getEavEntityType(), $this->searchCriteriaBuilder->create());
$attributes = $searchResult->getItems();
$this->attributeCache->saveAttributes($entityType, $attributes);
return $attributes;
}
开发者ID:Doability,项目名称:magento2dev,代码行数:17,代码来源:ReadHandler.php
示例20: toOptionArray
/**
* Return array of customer groups
*
* @return array
*/
public function toOptionArray()
{
if (!$this->moduleManager->isEnabled('Magento_Customer')) {
return [];
}
$customerGroups = [['label' => __('ALL GROUPS'), 'value' => GroupInterface::CUST_GROUP_ALL]];
/** @var GroupInterface[] $groups */
$groups = $this->groupRepository->getList($this->searchCriteriaBuilder->create());
foreach ($groups->getItems() as $group) {
$customerGroups[] = ['label' => $group->getCode(), 'value' => $group->getId()];
}
return $customerGroups;
}
开发者ID:Doability,项目名称:magento2dev,代码行数:18,代码来源:Group.php
注:本文中的Magento\Framework\Api\SearchCriteriaBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论