示例#1
0
 /**
  * {@inheritdoc}
  */
 public function isAssignedToObjects()
 {
     $searchCriteria = $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField('tax_class_id')->setValue($this->getId())->create()])->create();
     $result = $this->groupService->searchGroups($searchCriteria);
     $items = $result->getItems();
     return !empty($items);
 }
示例#2
0
 /**
  * Invoke InvoiceCommentsList service
  *
  * @param int $id
  * @return \Magento\Sales\Service\V1\Data\CommentSearchResults
  */
 public function invoke($id)
 {
     $this->criteriaBuilder->addFilter(['eq' => $this->filterBuilder->setField('parent_id')->setValue($id)->create()]);
     $criteria = $this->criteriaBuilder->create();
     $comments = [];
     foreach ($this->commentRepository->find($criteria) as $comment) {
         $comments[] = $this->commentMapper->extractDto($comment);
     }
     return $this->searchResultsBuilder->setItems($comments)->setSearchCriteria($criteria)->setTotalCount(count($comments))->create();
 }
 /**
  * {@inheritdoc}
  */
 protected function _setDataValues(array $data)
 {
     if (isset($data[FilterGroup::FILTERS])) {
         $filters = [];
         foreach ($data[FilterGroup::FILTERS] as $filter) {
             $filters[] = $this->_filterBuilder->populateWithArray($filter)->create();
         }
         $data[FilterGroup::FILTERS] = $filters;
     }
     return parent::_setDataValues($data);
 }
示例#4
0
 /**
  * Retrieve all product tax class options.
  *
  * @param bool $withEmpty
  * @return array
  */
 public function getAllOptions($withEmpty = false)
 {
     if (!$this->_options) {
         $filter = $this->_filterBuilder->setField(TaxClass::KEY_TYPE)->setValue(\Magento\Tax\Service\V1\TaxClassServiceInterface::TYPE_PRODUCT)->create();
         $searchCriteria = $this->_searchCriteriaBuilder->addFilter([$filter])->create();
         $searchResults = $this->_taxClassService->searchTaxClass($searchCriteria);
         foreach ($searchResults->getItems() as $taxClass) {
             $this->_options[] = array('value' => $taxClass->getClassId(), 'label' => $taxClass->getClassName());
         }
     }
     if ($withEmpty) {
         return array_merge(array(array('value' => '0', 'label' => __('None'))), $this->_options);
     }
     return $this->_options;
 }
示例#5
0
 /**
  * test invoice comments list service
  */
 public function testInvoke()
 {
     $invoiceId = 1;
     $this->filterBuilderMock->expects($this->once())->method('setField')->with($this->equalTo('parent_id'))->will($this->returnSelf());
     $this->filterBuilderMock->expects($this->once())->method('setValue')->with($this->equalTo($invoiceId))->will($this->returnSelf());
     $this->filterBuilderMock->expects($this->once())->method('create')->will($this->returnValue('filter'));
     $this->criteriaBuilderMock->expects($this->once())->method('addFilter')->with($this->equalTo(['eq' => 'filter']))->will($this->returnSelf());
     $this->criteriaBuilderMock->expects($this->once())->method('create')->will($this->returnValue($this->searchCriteriaMock));
     $this->commentRepositoryMock->expects($this->once())->method('find')->with($this->equalTo($this->searchCriteriaMock))->will($this->returnValue([$this->invoiceCommentMock]));
     $this->commentMapperMock->expects($this->once())->method('extractDto')->with($this->equalTo($this->invoiceCommentMock))->will($this->returnValue($this->dataObjectMock));
     $this->searchResultsBuilderMock->expects($this->once())->method('setItems')->with($this->equalTo([$this->dataObjectMock]))->will($this->returnSelf());
     $this->searchResultsBuilderMock->expects($this->once())->method('setTotalCount')->with($this->equalTo(1))->will($this->returnSelf());
     $this->searchResultsBuilderMock->expects($this->once())->method('setSearchCriteria')->with($this->equalTo($this->searchCriteriaMock))->will($this->returnSelf());
     $this->searchResultsBuilderMock->expects($this->once())->method('create')->will($this->returnValue('expected-result'));
     $this->assertEquals('expected-result', $this->invoiceCommentsList->invoke($invoiceId));
 }
示例#6
0
 /**
  * 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->_customerService->searchCustomers($searchCriteria);
     /** @var \Magento\Customer\Service\V1\Data\CustomerDetails $customerDetails */
     foreach ($searchResults->getItems() as $customerDetails) {
         $customerData = $customerDetails->getCustomer();
         $customerAddresses = $customerDetails->getAddresses();
         /** Look for a company name defined in default billing address */
         $company = null;
         foreach ($customerAddresses as $customerAddress) {
             if ($customerAddress->isDefaultBilling()) {
                 $company = $customerAddress->getCompany();
                 break;
             }
         }
         $result[] = array('id' => 'customer/1/' . $customerData->getId(), 'type' => __('Customer'), 'name' => $this->_customerViewHelper->getCustomerName($customerData), 'description' => $company, 'url' => $this->_adminhtmlData->getUrl('customer/index/edit', array('id' => $customerData->getId())));
     }
     $this->setResults($result);
     return $this;
 }
示例#7
0
 /**
  * @param int $id
  * @param array $collectionIds
  * @param $conditionType
  * @dataProvider getDataProvider
  */
 public function testGet($id, array $collectionIds, $conditionType)
 {
     $filter = $this->getMock('Magento\\Framework\\Service\\V1\\Data\\Filter', ['getConditionType', 'getField', 'getValue'], [], '', false);
     $filter->expects($this->any())->method('getConditionType')->willReturn($conditionType);
     $this->filterBuilder->expects($this->once())->method('setField')->with('transaction_id')->willReturnSelf();
     $this->filterBuilder->expects($this->once())->method('setValue')->with($id)->willReturnSelf();
     $this->filterBuilder->expects($this->once())->method('setConditionType')->with('eq')->willReturnSelf();
     $this->filterBuilder->expects($this->once())->method('create')->willReturn($filter);
     $filterGroup = $this->getMock('Magento\\Framework\\Service\\V1\\Data\\Search\\FilterGroup', [], [], '', false);
     $filterGroup->expects($this->any())->method('getFilters')->willReturn($filter);
     $searchCriteria = $this->getMock('Magento\\Framework\\Service\\V1\\Data\\SearchCriteria', [], [], '', false);
     $searchCriteria->expects($this->any())->method('getFilterGroups')->willReturn([$filterGroup]);
     $this->searchCriteriaBuilder->expects($this->once())->method('addFilter')->with([$filter]);
     $this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria);
     $transactionModelMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Payment\\Transaction')->disableOriginalConstructor()->setMethods([])->getMock();
     $transactionModelMock->expects($this->any())->method('getId')->will($this->returnValue($id));
     $this->prepareCollection($transactionModelMock, $collectionIds);
     $this->assertSame($transactionModelMock, $this->transactionRepository->get($id));
 }
 /**
  * Creates a filter DTO for given field/condition
  *
  * @param string $field Field for new filter
  * @param string|array $condition Condition for new filter.
  * @return Filter
  */
 protected function createFilterData($field, $condition)
 {
     $this->filterBuilder->setField($field);
     if (is_array($condition)) {
         $this->filterBuilder->setValue(reset($condition));
         $this->filterBuilder->setConditionType(key($condition));
     } else {
         // not an array, just use eq as condition type and given value
         $this->filterBuilder->setConditionType('eq');
         $this->filterBuilder->setValue($condition);
     }
     return $this->filterBuilder->create();
 }
示例#9
0
 /**
  * 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];
 }
示例#10
0
 /**
  * {@inheritdoc}
  */
 public function getTaxClassId($taxClassKey, $taxClassType = TaxClassServiceInterface::TYPE_PRODUCT)
 {
     if (!empty($taxClassKey)) {
         switch ($taxClassKey->getType()) {
             case TaxClassKey::TYPE_ID:
                 return $taxClassKey->getValue();
             case TaxClassKey::TYPE_NAME:
                 $searchCriteria = $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField(TaxClass::KEY_TYPE)->setValue($taxClassType)->create()])->addFilter([$this->filterBuilder->setField(TaxClass::KEY_NAME)->setValue($taxClassKey->getValue())->create()])->create();
                 $taxClasses = $this->searchTaxClass($searchCriteria)->getItems();
                 $taxClass = array_shift($taxClasses);
                 return null == $taxClass ? null : $taxClass->getClassId();
             default:
         }
     }
     return null;
 }
 public function testGetSearchCriteriaAnd()
 {
     // Test ((A > 1) and (B > 1))
     $fieldA = 'A';
     $fieldB = 'B';
     $value = 1;
     /** @var SearchCriteria $expectedSearchCriteria */
     $expectedSearchCriteria = $this->searchCriteriaBuilder->setCurrentPage(1)->setPageSize(0)->addSortOrder('name', SearchCriteria::SORT_ASC)->addFilter([$this->filterBuilder->setField($fieldA)->setConditionType('gt')->setValue($value)->create()])->addFilter([$this->filterBuilder->setField($fieldB)->setConditionType('gt')->setValue($value)->create()])->create();
     // Verifies that the search criteria Data Object created by the serviceCollection matches expected
     $this->groupServiceMock->expects($this->once())->method('searchGroups')->with($this->equalTo($expectedSearchCriteria))->will($this->returnValue($this->searchResults));
     // Now call service collection to load the data.  This causes it to create the search criteria Data Object
     $this->serviceCollection->addFieldToFilter($fieldA, ['gt' => $value]);
     $this->serviceCollection->addFieldToFilter($fieldB, ['gt' => $value]);
     $this->serviceCollection->setOrder('name', ServiceCollection::SORT_ORDER_ASC);
     $this->serviceCollection->loadData();
 }
示例#12
0
 /**
  * {@inheritdoc}
  */
 public function getRatesByCustomerAndProductTaxClassId($customerTaxClassId, $productTaxClassId)
 {
     $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField(TaxRule::CUSTOMER_TAX_CLASS_IDS)->setValue([$customerTaxClassId])->create()]);
     $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField(TaxRule::PRODUCT_TAX_CLASS_IDS)->setValue([$productTaxClassId])->create()]);
     $searchResults = $this->searchTaxRules($this->searchCriteriaBuilder->create());
     $taxRules = $searchResults->getItems();
     $rates = [];
     foreach ($taxRules as $taxRule) {
         $rateIds = $taxRule->getTaxRateIds();
         if (!empty($rateIds)) {
             foreach ($rateIds as $rateId) {
                 $rates[] = $this->taxRateService->getTaxRate($rateId);
             }
         }
     }
     return $rates;
 }
示例#13
0
 /**
  * Retrieve EAV attribute metadata of category
  *
  * @param int $attributeSetId
  * @return AttributeMetadata[]
  */
 public function getCategoryAttributesMetadata($attributeSetId = MetadataServiceInterface::DEFAULT_ATTRIBUTE_SET_ID)
 {
     $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField('attribute_set_id')->setValue($attributeSetId)->create()]);
     return $this->metadataService->getAllAttributeMetadata(MetadataServiceInterface::ENTITY_TYPE, $this->searchCriteriaBuilder->create())->getItems();
 }
示例#14
0
 /**
  * Retrieve EAV attribute metadata of product
  *
  * @param int $attributeSetId
  * @return AttributeMetadata[]
  */
 public function getProductAttributesMetadata($attributeSetId = self::DEFAULT_ATTRIBUTE_SET_ID)
 {
     /** @var \Magento\Framework\Service\V1\Data\SearchCriteriaBuilder $searchCriteria */
     $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField('attribute_set_id')->setValue($attributeSetId)->create()]);
     return $this->metadataService->getAllAttributeMetadata(MetadataServiceInterface::ENTITY_TYPE, $this->searchCriteriaBuilder->create())->getItems();
 }