Esempio n. 1
0
 /**
  * {@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->addFilters([$this->filterBuilder->setField(ClassModel::KEY_TYPE)->setValue($taxClassType)->create()])->addFilters([$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;
 }
 /**
  * @return void
  */
 public function testGetList()
 {
     $taxClassOne = $this->getMock('\\Magento\\Tax\\Api\\Data\\TaxClassInterface');
     $taxClassTwo = $this->getMock('\\Magento\\Tax\\Api\\Data\\TaxClassInterface');
     $searchCriteria = $this->getMock('\\Magento\\Framework\\Api\\SearchCriteriaInterface');
     $filterGroup = $this->getMock('\\Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false);
     $filter = $this->getMock('\\Magento\\Framework\\Api\\Filter', [], [], '', false);
     $collection = $this->getMock('\\Magento\\Tax\\Model\\ResourceModel\\TaxClass\\Collection', [], [], '', false);
     $sortOrder = $this->getMock('\\Magento\\Framework\\Api\\SortOrder', [], [], '', false);
     $this->extensionAttributesJoinProcessorMock->expects($this->once())->method('process')->with($collection);
     $searchCriteria->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroup]);
     $filterGroup->expects($this->once())->method('getFilters')->willReturn([$filter]);
     $filter->expects($this->atLeastOnce())->method('getConditionType')->willReturn('eq');
     $filter->expects($this->once())->method('getField')->willReturn('field');
     $filter->expects($this->once())->method('getValue')->willReturn('value');
     $collection->expects($this->once())->method('addFieldToFilter')->with(['field'], [['eq' => 'value']]);
     $searchCriteria->expects($this->exactly(2))->method('getSortOrders')->willReturn([$sortOrder]);
     $sortOrder->expects($this->once())->method('getField')->willReturn('field');
     $sortOrder->expects($this->once())->method('getDirection')->willReturn(SortOrder::SORT_ASC);
     $collection->expects($this->once())->method('addOrder')->with('field', 'ASC');
     $searchCriteria->expects($this->once())->method('getPageSize')->willReturn(20);
     $searchCriteria->expects($this->once())->method('getCurrentPage')->willReturn(0);
     $collection->expects($this->any())->method('getSize')->willReturn(2);
     $collection->expects($this->any())->method('setItems')->with([$taxClassOne, $taxClassTwo]);
     $collection->expects($this->any())->method('getItems')->willReturn([$taxClassOne, $taxClassTwo]);
     $collection->expects($this->once())->method('setCurPage')->with(0);
     $collection->expects($this->once())->method('setPageSize')->with(20);
     $this->searchResultMock->expects($this->once())->method('setSearchCriteria')->with($searchCriteria);
     $this->searchResultMock->expects($this->once())->method('setTotalCount')->with(2);
     $this->searchResultFactory->expects($this->once())->method('create')->willReturn($this->searchResultMock);
     $this->taxClassCollectionFactory->expects($this->once())->method('create')->willReturn($collection);
     $this->assertEquals($this->searchResultMock, $this->model->getList($searchCriteria));
 }
Esempio n. 3
0
 /**
  * @magentoDbIsolation enabled
  */
 public function testGetList()
 {
     $taxClassName = 'Get Me';
     $taxClassDataObject = $this->taxClassFactory->create();
     $taxClassDataObject->setClassName($taxClassName)->setClassType(TaxClassManagementInterface::TYPE_CUSTOMER);
     $taxClassId = $this->taxClassRepository->save($taxClassDataObject);
     /** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder */
     $searchCriteriaBuilder = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\SearchCriteriaBuilder');
     /** @var \Magento\Tax\Api\Data\TaxClassSearchResultsInterface */
     $searchResult = $this->taxClassRepository->getList($searchCriteriaBuilder->create());
     $items = $searchResult->getItems();
     /** @var \Magento\Tax\Api\Data\TaxClassInterface */
     $taxClass = array_pop($items);
     $this->assertInstanceOf('Magento\\Tax\\Api\\Data\\TaxClassInterface', $taxClass);
     $this->assertEquals($taxClassName, $taxClass->getClassName());
     $this->assertEquals($taxClassId, $taxClass->getClassId());
     $this->assertEquals(TaxClassManagementInterface::TYPE_CUSTOMER, $taxClass->getClassType());
 }