作者:pradeep-wagent
项目:magento
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]);
}
作者:Doabilit
项目:magento2de
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]);
}
作者:nh
项目:MageTitans_ProductStatu
/**
* @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)]);
}, []);
}
作者:shabbirvividad
项目:magento
/**
* {@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);
}
作者:pradeep-wagent
项目:magento
/**
* 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;
}
作者:tingyee
项目:magento
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));
}
作者:opexs
项目:magento
/**
* 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());
}
}
作者:Doabilit
项目:magento2de
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));
}
作者:kidaa3
项目:magento2-platforms
/**
* {@inheritdoc}
*/
public function init($context)
{
foreach ($this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems() as $group) {
$this->customerGroups[$group->getId()] = true;
}
return parent::init($context);
}
作者:pradeep-wagent
项目:magento
/**
* {@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);
}
作者:pradeep-wagent
项目:magento
/**
* 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;
}
作者:stepzerosolution
项目:tbslide
/**
* 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;
}
作者:Vina
项目:MM15PL_ProductStatu
/**
* @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)]);
}, []);
}
作者:imbr
项目:magento2-sample
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());
}
作者:hientruong9
项目:magento2_installe
/**
* 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;
}
作者:Doabilit
项目:magento2de
/**
* 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;
}
作者:Doabilit
项目:magento2de
/**
* 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] : '']]]]]]];
}
作者:pradeep-wagent
项目:magento
/**
* @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');
}
作者:Doabilit
项目:magento2de
/**
* @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;
}
作者:Doabilit
项目:magento2de
/**
* 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;
}