Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function deleteById($rateId)
 {
     $rateModel = $this->rateRegistry->retrieveTaxRate($rateId);
     $this->delete($rateModel);
     $this->rateRegistry->removeTaxRate($rateId);
     return true;
 }
 public function testRemoveTaxRate()
 {
     $this->rateModelMock->expects($this->any())->method('load')->with(self::TAX_RATE_ID)->will($this->returnValue($this->rateModelMock));
     // The second time this is called, want it to return null indicating a new object
     $this->rateModelMock->expects($this->any())->method('getId')->will($this->onConsecutiveCalls(self::TAX_RATE_ID, null));
     $this->rateModelFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->rateModelMock));
     $actual = $this->rateRegistry->retrieveTaxRate(self::TAX_RATE_ID);
     $this->assertEquals($this->rateModelMock, $actual);
     // Remove the rate
     $this->rateRegistry->removeTaxRate(self::TAX_RATE_ID);
     // Verify that if the rate is retrieved again, an exception is thrown
     try {
         $this->rateRegistry->retrieveTaxRate(self::TAX_RATE_ID);
         $this->fail('NoSuchEntityException was not thrown as expected');
     } catch (NoSuchEntityException $e) {
         $expectedParams = ['fieldName' => 'taxRateId', 'fieldValue' => self::TAX_RATE_ID];
         $this->assertEquals($expectedParams, $e->getParameters());
     }
 }
Exemple #3
0
 /**
  * Save Tax Rate
  *
  * @param TaxRateDataObject $taxRate
  * @throws InputException
  * @throws ModelException
  * @return RateModel
  */
 protected function saveTaxRate(TaxRateDataObject $taxRate)
 {
     $this->validate($taxRate);
     $taxRateModel = $this->converter->createTaxRateModel($taxRate);
     $taxRateTitles = $this->converter->createTitleArrayFromServiceObject($taxRate);
     try {
         $taxRateModel->save();
         $taxRateModel->saveTitles($taxRateTitles);
     } catch (ModelException $e) {
         if ($e->getCode() == ModelException::ERROR_CODE_ENTITY_ALREADY_EXISTS) {
             throw new InputException($e->getMessage());
         } else {
             throw $e;
         }
     }
     $this->rateRegistry->registerTaxRate($taxRateModel);
     return $taxRateModel;
 }