public function testGetTaxClass()
 {
     $taxClassId = 1;
     $this->classModelMock->expects($this->exactly(2))->method('getId')->will($this->returnValue($taxClassId));
     $this->classModelMock->expects($this->once())->method('load')->with($taxClassId)->will($this->returnValue($this->classModelMock));
     $this->assertEquals($this->classModelMock, $this->taxRuleRegistry->retrieve($taxClassId));
 }
예제 #2
0
 /**
  * Create new config object
  *
  * @param \Magento\Tax\Model\ClassModel $taxClass
  * @return \Magento\Tax\Model\TaxClass\Type\TypeInterface
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function create(\Magento\Tax\Model\ClassModel $taxClass)
 {
     $taxClassType = $taxClass->getClassType();
     if (!array_key_exists($taxClassType, $this->_types)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Invalid type of tax class "%1"', $taxClassType));
     }
     return $this->_objectManager->create($this->_types[$taxClassType], ['data' => ['id' => $taxClass->getId()]]);
 }
예제 #3
0
파일: Factory.php 프로젝트: aiesh/magento2
 /**
  * Create new config object
  *
  * @param \Magento\Tax\Model\ClassModel $taxClass
  * @return \Magento\Tax\Model\TaxClass\Type\TypeInterface
  * @throws \Magento\Framework\Model\Exception
  */
 public function create(\Magento\Tax\Model\ClassModel $taxClass)
 {
     $taxClassType = $taxClass->getClassType();
     if (!array_key_exists($taxClassType, $this->_types)) {
         throw new \Magento\Framework\Model\Exception(sprintf('Invalid type of tax class "%s"', $taxClassType));
     }
     return $this->_objectManager->create($this->_types[$taxClassType], array('data' => array('id' => $taxClass->getId())));
 }
예제 #4
0
 /**
  * @magentoDbIsolation enabled
  * @expectedException \Magento\Framework\Exception\InputException
  * @expectedExceptionMessage Updating classType is not allowed.
  */
 public function testUpdateTaxClassWithChangingClassType()
 {
     $taxClassName = 'New Class Name';
     $taxClassDataObject = $this->taxClassBuilder->setClassName($taxClassName)->setClassType(TaxClassModel::TAX_CLASS_TYPE_CUSTOMER)->create();
     $taxClassId = $this->taxClassService->createTaxClass($taxClassDataObject);
     $this->assertEquals($taxClassName, $this->taxClassModel->load($taxClassId)->getClassName());
     $updatedTaxClassName = 'Updated Class Name';
     $taxClassDataObject = $this->taxClassBuilder->setClassName($updatedTaxClassName)->setClassType(TaxClassModel::TAX_CLASS_TYPE_PRODUCT)->create();
     $this->taxClassService->updateTaxClass($taxClassId, $taxClassDataObject);
 }
예제 #5
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);
 }
예제 #6
0
 /**
  * Convert tax class model into tax class service data object.
  *
  * @param TaxClassModel $taxClassModel
  * @return TaxClass
  */
 public function createTaxClassData(TaxClassModel $taxClassModel)
 {
     return $this->taxClassDataObjectFactory->create()->setClassId($taxClassModel->getId())->setClassName($taxClassModel->getClassName())->setClassType($taxClassModel->getClassType());
 }
예제 #7
0
 public function testDeleteModelDeleteSuccess()
 {
     $taxClassId = 1;
     $this->taxClassModelMock->expects($this->once())->method('delete');
     $this->assertTrue($this->taxClassService->deleteTaxClass($taxClassId));
 }
예제 #8
0
 /**
  * Convert tax class model into tax class service data object.
  *
  * @param TaxClassModel $taxClassModel
  * @return TaxClass
  */
 public function createTaxClassData(TaxClassModel $taxClassModel)
 {
     $this->taxClassBuilder->setClassId($taxClassModel->getId())->setClassName($taxClassModel->getClassName())->setClassType($taxClassModel->getClassType());
     return $this->taxClassBuilder->create();
 }
예제 #9
0
 /**
  * Add tax class model to the registry
  *
  * @param TaxClassModel $taxClassModel
  * @return void
  */
 public function registerTaxClass(TaxClassModel $taxClassModel)
 {
     $this->taxClassRegistryById[$taxClassModel->getId()] = $taxClassModel;
 }