/** * {@inheritdoc} */ public function save(\Magento\Tax\Api\Data\TaxRateInterface $taxRate) { if ($taxRate->getId()) { $this->rateRegistry->retrieveTaxRate($taxRate->getId()); } $this->validate($taxRate); $taxRateTitles = $this->converter->createTitleArrayFromServiceObject($taxRate); try { $this->resourceModel->save($taxRate); $taxRate->saveTitles($taxRateTitles); } catch (LocalizedException $e) { throw $e; } $this->rateRegistry->registerTaxRate($taxRate); return $taxRate; }
/** * 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; }
public function testRegisterTaxRate() { $this->rateModelMock->expects($this->any())->method('getId')->will($this->returnValue(self::TAX_RATE_ID)); $this->rateRegistry->registerTaxRate($this->rateModelMock); $this->assertEquals($this->rateModelMock, $this->rateRegistry->retrieveTaxRate(self::TAX_RATE_ID)); }