/** * @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)]); }, []); }
/** * 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->addFilter('attribute_set_id', null, 'neq')->create()); $attributes = []; foreach ($searchResult->getItems() as $attribute) { $attributes[] = $attribute->getAttributeCode(); } return $attributes; }
/** * 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->addFilter($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; }
/** * {@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); }
/** * @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)]); }, []); }
/** * 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; }
/** * @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->addFilter([$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'); }
/** * {@inheritdoc} */ public function getByIdentifierNamespace($identifier, $namespace) { $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField('user_id')->setConditionType('eq')->setValue($this->userContext->getUserId())->create(), $this->filterBuilder->setField('identifier')->setConditionType('eq')->setValue($identifier)->create(), $this->filterBuilder->setField('namespace')->setConditionType('eq')->setValue($namespace)->create()]); $searchCriteria = $this->searchCriteriaBuilder->create(); $searchResults = $this->bookmarkRepository->getList($searchCriteria); if ($searchResults->getTotalCount() > 0) { foreach ($searchResults->getItems() as $searchResult) { $bookmark = $this->bookmarkRepository->getById($searchResult->getId()); return $bookmark; } } return null; }
/** * Get a list of current customer addresses. * * @return \Magento\Customer\Api\Data\AddressInterface[] */ public function getAddress() { $addresses = $this->getData('address_collection'); if ($addresses === null) { try { $filter = $this->filterBuilder->setField('parent_id')->setValue($this->_multishipping->getCustomer()->getId())->setConditionType('eq')->create(); $addresses = (array) $this->addressRepository->getList($this->searchCriteriaBuilder->addFilter([$filter])->create())->getItems(); } catch (NoSuchEntityException $e) { return []; } $this->setData('address_collection', $addresses); } return $addresses; }
/** * Retrieve all customer tax classes as an options array. * * @return array * @throws StateException */ public function getAllOptions() { if (empty($this->_options)) { $options = []; $filter = $this->filterBuilder->setField(TaxClass::KEY_TYPE)->setValue(TaxClassManagementInterface::TYPE_CUSTOMER)->create(); $searchCriteria = $this->searchCriteriaBuilder->addFilter([$filter])->create(); $searchResults = $this->taxClassRepository->getList($searchCriteria); foreach ($searchResults->getItems() as $taxClass) { $options[] = ['value' => $taxClass->getClassId(), 'label' => $taxClass->getClassName()]; } $this->_options = $options; } return $this->_options; }
/** * load entity * * @param int $id * @return Transaction * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\InputException */ public function get($id) { if (!$id) { throw new \Magento\Framework\Exception\InputException(__('ID required')); } if (!isset($this->registry[$id])) { $filter = $this->filterBuilder->setField('transaction_id')->setValue($id)->setConditionType('eq')->create(); $this->searchCriteriaBuilder->addFilter([$filter]); $this->find($this->searchCriteriaBuilder->create()); if (!isset($this->registry[$id])) { throw new \Magento\Framework\Exception\NoSuchEntityException(__('Requested entity doesn\'t exist')); } } return $this->registry[$id]; }
/** * {@inheritdoc} */ public function getTaxClassId($taxClassKey, $taxClassType = self::TYPE_PRODUCT) { if (!empty($taxClassKey)) { switch ($taxClassKey->getType()) { case TaxClassKeyInterface::TYPE_ID: return $taxClassKey->getValue(); case TaxClassKeyInterface::TYPE_NAME: $searchCriteria = $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField(ClassModel::KEY_TYPE)->setValue($taxClassType)->create()])->addFilter([$this->filterBuilder->setField(ClassModel::KEY_NAME)->setValue($taxClassKey->getValue())->create()])->create(); $taxClasses = $this->classRepository->getList($searchCriteria)->getItems(); $taxClass = array_shift($taxClasses); return null == $taxClass ? null : $taxClass->getClassId(); } } return null; }
/** * {@inheritdoc} */ public function getLoggedInGroups() { $notLoggedInFilter[] = $this->filterBuilder->setField(GroupInterface::ID)->setConditionType('neq')->setValue(self::NOT_LOGGED_IN_ID)->create(); $groupAll[] = $this->filterBuilder->setField(GroupInterface::ID)->setConditionType('neq')->setValue(self::CUST_GROUP_ALL)->create(); $searchCriteria = $this->searchCriteriaBuilder->addFilter($notLoggedInFilter)->addFilter($groupAll)->create(); return $this->groupRepository->getList($searchCriteria)->getItems(); }
/** * 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->addFilter([$filter1, $filter2]); $this->searchCriteriaBuilder->addFilter([$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->addFilter([$filter2]); $this->searchCriteriaBuilder->addFilter([$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]); }
/** * 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->addFilter([$filter1]); $this->searchCriteriaBuilder->addFilter([$filter2, $filter3]); $this->searchCriteriaBuilder->addFilter([$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->addFilter([$filter1]); $this->searchCriteriaBuilder->addFilter([$filter2, $filter3]); $this->searchCriteriaBuilder->addFilter([$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']); }
/** * 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(); }
/** * {@inheritdoc} */ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) { /** @var \Magento\Catalog\Model\Resource\Product\Collection $collection */ $collection = $this->collectionFactory->create(); $defaultAttributeSetId = $this->eavConfig->getEntityType(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE)->getDefaultAttributeSetId(); $extendedSearchCriteria = $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField('attribute_set_id')->setValue($defaultAttributeSetId)->create()]); foreach ($this->metadataService->getList($extendedSearchCriteria->create())->getItems() as $metadata) { $collection->addAttributeToSelect($metadata->getAttributeCode()); } $collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner'); $collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner'); //Add filters from root filter group to the collection foreach ($searchCriteria->getFilterGroups() as $group) { $this->addFilterGroupToCollection($group, $collection); } /** @var SortOrder $sortOrder */ foreach ((array) $searchCriteria->getSortOrders() as $sortOrder) { $field = $sortOrder->getField(); $collection->addOrder($field, $sortOrder->getDirection() == SearchCriteriaInterface::SORT_ASC ? 'ASC' : 'DESC'); } $collection->setCurPage($searchCriteria->getCurrentPage()); $collection->setPageSize($searchCriteria->getPageSize()); $collection->load(); $searchResult = $this->searchResultsFactory->create(); $searchResult->setSearchCriteria($searchCriteria); $searchResult->setItems($collection->getItems()); $searchResult->setTotalCount($collection->getSize()); return $searchResult; }
/** * {@inheritdoc} */ public function getRatesByCustomerAndProductTaxClassId($customerTaxClassId, $productTaxClassId) { $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField('customer_tax_class_ids')->setValue([$customerTaxClassId])->create()]); $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField('product_tax_class_ids')->setValue([$productTaxClassId])->create()]); $searchResults = $this->taxRuleRepository->getList($this->searchCriteriaBuilder->create()); $taxRules = $searchResults->getItems(); $rates = []; foreach ($taxRules as $taxRule) { $rateIds = $taxRule->getTaxRateIds(); if (!empty($rateIds)) { foreach ($rateIds as $rateId) { $rates[] = $this->taxRateRepository->get($rateId); } } } return $rates; }
/** * @expectedException \Exception */ public function testGetListThrowsExceptionIfProvidedSearchFieldIsInvalid() { $serviceInfo = ['soap' => ['service' => 'quoteCartRepositoryV1', 'serviceVersion' => 'V1', 'operation' => 'quoteCartRepositoryV1GetList'], 'rest' => ['resourcePath' => '/V1/carts', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT]]; $invalidFilter = $this->filterBuilder->setField('invalid_field')->setConditionType('eq')->setValue(0)->create(); $this->searchBuilder->addFilter([$invalidFilter]); $searchCriteria = $this->searchBuilder->create()->__toArray(); $requestData = ['searchCriteria' => $searchCriteria]; $this->_webApiCall($serviceInfo, $requestData); }
/** * Retrieve all product tax class options. * * @param bool $withEmpty * @return array */ public function getAllOptions($withEmpty = true) { if (!$this->_options) { $filter = $this->_filterBuilder->setField(TaxClass::KEY_TYPE)->setValue(TaxClassManagementInterface::TYPE_PRODUCT)->create(); $searchCriteria = $this->_searchCriteriaBuilder->addFilter([$filter])->create(); $searchResults = $this->_taxClassRepository->getList($searchCriteria); foreach ($searchResults->getItems() as $taxClass) { $this->_options[] = ['value' => $taxClass->getClassId(), 'label' => $taxClass->getClassName()]; } } if ($withEmpty) { if (!$this->_options) { return [['value' => '0', 'label' => __('None')]]; } else { return array_merge([['value' => '0', 'label' => __('None')]], $this->_options); } } return $this->_options; }
/** * Retrieve current customer address DATA collection. * * @return \Magento\Customer\Api\Data\AddressInterface[] */ public function getAddressCollection() { if ($this->getCustomerId()) { $filter = $this->filterBuilder->setField('parent_id')->setValue($this->getCustomerId())->setConditionType('eq')->create(); $this->criteriaBuilder->addFilter([$filter]); $criteria = $this->criteriaBuilder->create(); $result = $this->addressService->getList($criteria); return $result->getItems(); } return []; }
/** * Get attribute codes of prev set * * @return array * @throws \Magento\Framework\Exception\LocalizedException */ private function getPreviousSetAttributes() { if ($this->prevSetAttributes === null) { $searchCriteria = $this->searchCriteriaBuilder->addFilter('attribute_set_id', $this->getPreviousSetId())->create(); $attributes = $this->attributeRepository->getList($searchCriteria)->getItems(); $this->prevSetAttributes = []; foreach ($attributes as $attribute) { $this->prevSetAttributes[] = $attribute->getAttributeCode(); } } return $this->prevSetAttributes; }
/** * @magentoApiDataFixture Magento/Tax/_files/tax_classes.php */ public function testSearchTaxRule() { $fixtureRule = $this->getFixtureTaxRules()[0]; $filter = $this->filterBuilder->setField('code')->setValue($fixtureRule->getCode())->create(); $this->searchCriteriaBuilder->addFilter([$filter]); $searchData = $this->searchCriteriaBuilder->create()->__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($fixtureRule->getId(), $searchResults['items'][0]["id"]); $this->assertEquals($fixtureRule->getCode(), $searchResults['items'][0]['code']); }
/** * @magentoApiDataFixture Magento/Sales/_files/invoice.php */ public function testAutoGeneratedGetList() { $this->getExpectedExtensionAttributes(); /** @var SortOrder $sortOrder */ $sortOrder = $this->sortOrderBuilder->setField('store_id')->setDirection(SearchCriteria::SORT_ASC)->create(); $this->searchBuilder->setSortOrders([$sortOrder]); $this->searchBuilder->addFilter([$this->filterBuilder->setField('state')->setValue(2)->create()]); $searchCriteria = $this->searchBuilder->create()->__toArray(); $requestData = ['criteria' => $searchCriteria]; $restResourcePath = '/V1/invoices/'; $soapService = 'salesInvoiceRepositoryV1'; $expectedExtensionAttributes = $this->getExpectedExtensionAttributes(); $serviceInfo = ['rest' => ['resourcePath' => $restResourcePath . '?' . http_build_query($requestData), 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET], 'soap' => ['service' => $soapService, 'operation' => $soapService . 'GetList']]; $searchResult = $this->_webApiCall($serviceInfo, $requestData); $this->assertArrayHasKey('items', $searchResult); $itemData = array_pop($searchResult['items']); $this->assertArrayHasKey('extension_attributes', $itemData); $this->assertArrayHasKey('invoice_api_test_attribute', $itemData['extension_attributes']); $testAttribute = $itemData['extension_attributes']['invoice_api_test_attribute']; $this->assertEquals($expectedExtensionAttributes['firstname'], $testAttribute['first_name']); $this->assertEquals($expectedExtensionAttributes['lastname'], $testAttribute['last_name']); $this->assertEquals($expectedExtensionAttributes['email'], $testAttribute['email']); }
/** * Get custom attributes * * @param string $entityType * @return \Magento\Eav\Api\Data\AttributeInterface[] * @throws \Exception */ private function getNonStaticAttributes($entityType) { if (!isset($this->attributes[$entityType])) { $metadata = $this->metadataPool->getMetadata($entityType); $searchResult = $this->attributeRepository->getList($metadata->getEavEntityType(), $this->searchCriteriaBuilder->addFilter('attribute_set_id', null, 'neq')->create()); $attributes = []; foreach ($searchResult->getItems() as $attribute) { if (!$attribute->isStatic()) { $attributes[] = $attribute; } } $this->attributes[$entityType] = $attributes; } return $this->attributes[$entityType]; }
/** * @param array $filters * @param array $filterGroup * @param array $expectedResult array of expected results indexed by ID * * @dataProvider searchGroupsDataProvider */ public function testGetList($filters, $filterGroup, $expectedResult) { foreach ($filters as $filter) { $this->searchCriteriaBuilder->addFilter([$filter]); } if ($filterGroup !== null) { $this->searchCriteriaBuilder->addFilter($filterGroup); } $searchResults = $this->groupRepository->getList($this->searchCriteriaBuilder->create()); /** @var $item GroupInterface */ foreach ($searchResults->getItems() as $item) { $this->assertEquals($expectedResult[$item->getId()][GroupInterface::CODE], $item->getCode()); $this->assertEquals($expectedResult[$item->getId()][GroupInterface::TAX_CLASS_ID], $item->getTaxClassId()); unset($expectedResult[$item->getId()]); } }
/** * getItems method * * @return array */ public function getItems() { $result = []; $query = $this->queryFactory->get()->getQueryText(); $productIds = $this->searchProductsFullText($query); // Check if products are found if ($productIds) { $searchCriteria = $this->searchCriteriaBuilder->addFilter('entity_id', $productIds, 'in')->create(); $products = $this->productRepository->getList($searchCriteria); foreach ($products->getItems() as $product) { $image = $this->imageHelper->init($product, 'product_page_image_small')->getUrl(); $resultItem = $this->itemFactory->create(['title' => $product->getName(), 'price' => $this->priceCurrency->format($product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(), false), 'special_price' => $this->priceCurrency->format($product->getPriceInfo()->getPrice('special_price')->getAmount()->getValue(), false), 'has_special_price' => $product->getSpecialPrice() > 0 ? true : false, 'image' => $image, 'url' => $product->getProductUrl()]); $result[] = $resultItem; } } return $result; }
/** * {@inheritdoc} */ public function getItems() { $result = []; $query = $this->queryFactory->get()->getQueryText(); $productIds = $this->searchProductsFullText($query); // Check if products are found if ($productIds) { $searchCriteria = $this->searchCriteriaBuilder->addFilter('entity_id', $productIds, 'in')->create(); $products = $this->productRepository->getList($searchCriteria); $baseUrl = $this->storeManager->getStore()->getBaseUrl(); // Loop through products foreach ($products->getItems() as $product) { $resultItem = $this->itemFactory->create(['title' => $product->getName(), 'price' => $this->priceCurrency->format($product->getFinalPrice(), false), 'special_price' => $this->priceCurrency->format($product->getSpecialPrice(), false), 'has_special_price' => $product->getSpecialPrice() > 0 ? true : false, 'image' => str_replace('index.php/', '', $baseUrl) . '/pub/media/catalog/product' . $product->getImage(), 'url' => $product->getProductUrl()]); $result[] = $resultItem; } } return $result; }
/** * @param CustomerInterface $entity * @return CustomerInterface * @throws \Exception * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute($entity, $arguments = []) { $searchCriteria = $this->searchCriteriaBuilder->addFilter('parent_id', $entity->getId())->create(); $addressesResult = $this->addressRepository->getList($searchCriteria); $entity->setAddresses($addressesResult->getItems()); return $entity; }
/** * {@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()); }