Пример #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;
 }
Пример #2
0
 /**
  * @magentoDbIsolation enabled
  */
 public function testGetTaxClassId()
 {
     $taxClassName = 'Get Me';
     $taxClassDataObject = $this->taxClassFactory->create();
     $taxClassDataObject->setClassName($taxClassName)->setClassType(TaxClassManagementInterface::TYPE_CUSTOMER);
     $taxClassId = $this->taxClassRepository->save($taxClassDataObject);
     /** @var \Magento\Tax\Api\Data\TaxClassKeyInterfaceFactory $taxClassKeyFactory */
     $taxClassKeyFactory = $this->objectManager->create('Magento\\Tax\\Api\\Data\\TaxClassKeyInterfaceFactory');
     $taxClassKeyTypeId = $taxClassKeyFactory->create();
     $this->dataObjectHelper->populateWithArray($taxClassKeyTypeId, [TaxClassKeyInterface::KEY_TYPE => TaxClassKeyInterface::TYPE_ID, TaxClassKeyInterface::KEY_VALUE => $taxClassId], '\\Magento\\Tax\\Api\\Data\\TaxClassKeyInterface');
     $this->assertEquals($taxClassId, $this->taxClassManagement->getTaxClassId($taxClassKeyTypeId, TaxClassManagementInterface::TYPE_CUSTOMER));
     $taxClassKeyTypeName = $taxClassKeyFactory->create();
     $this->dataObjectHelper->populateWithArray($taxClassKeyTypeName, [TaxClassKeyInterface::KEY_TYPE => TaxClassKeyInterface::TYPE_NAME, TaxClassKeyInterface::KEY_VALUE => $taxClassName], '\\Magento\\Tax\\Api\\Data\\TaxClassKeyInterface');
     $this->assertEquals($taxClassId, $this->taxClassManagement->getTaxClassId($taxClassKeyTypeId, TaxClassManagementInterface::TYPE_CUSTOMER));
     $this->assertNull($this->taxClassManagement->getTaxClassId(null));
     $this->assertEquals(null, $this->taxClassManagement->getTaxClassId($taxClassKeyTypeName, TaxClassManagementInterface::TYPE_PRODUCT));
 }
Пример #3
0
 /**
  * @param string $classType
  * @return void
  * @dataProvider validateTaxClassDataProvider
  * @expectedException \Magento\Framework\Exception\InputException
  * @expectedExceptionMessage One or more input exceptions have occurred.
  */
 public function testSaveWithValidateTaxClassDataException($classType)
 {
     $taxClass = $this->getMock('\\Magento\\Tax\\Model\\ClassModel', [], [], '', false);
     $taxClass->expects($this->any())->method('getClassName')->willReturn('');
     $taxClass->expects($this->atLeastOnce())->method('getClassType')->willReturn($classType);
     $taxClass->expects($this->any())->method('getClassId')->willReturn(10);
     $originTaxClass = $this->getMock('\\Magento\\Tax\\Model\\ClassModel', [], [], '', false);
     $originTaxClass->expects($this->once())->method('getClassType')->willReturn($classType);
     $this->classModelRegistryMock->expects($this->once())->method('retrieve')->with(10)->willReturn($originTaxClass);
     $this->model->save($taxClass);
 }
Пример #4
0
 /**
  * @magentoDbIsolation enabled
  * @expectedException \Magento\Framework\Exception\InputException
  * @expectedExceptionMessage Updating classType is not allowed.
  */
 public function testSaveThrowsExceptionIfTargetTaxClassHasDifferentClassType()
 {
     $taxClassName = 'New Class Name';
     $taxClassDataObject = $this->taxClassFactory->create();
     $taxClassDataObject->setClassName($taxClassName)->setClassType(TaxClassModel::TAX_CLASS_TYPE_CUSTOMER);
     $taxClassId = $this->taxClassRepository->save($taxClassDataObject);
     $this->assertEquals($taxClassName, $this->taxClassModel->load($taxClassId)->getClassName());
     $updatedTaxClassName = 'Updated Class Name';
     $taxClassDataObject = $this->taxClassFactory->create();
     $taxClassDataObject->setClassName($updatedTaxClassName)->setClassId($taxClassId)->setClassType(TaxClassModel::TAX_CLASS_TYPE_PRODUCT);
     $this->taxClassRepository->save($taxClassDataObject);
 }