Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RateRegistry.php
Go to the documentation of this file.
1 <?php
8 
11 use Magento\Tax\Model\Calculation\RateFactory as TaxRateModelFactory;
12 
14 {
20  private $taxRateModelFactory;
21 
27  private $taxRateRegistryById = [];
28 
34  public function __construct(
35  TaxRateModelFactory $taxModelRateFactory
36  ) {
37  $this->taxRateModelFactory = $taxModelRateFactory;
38  }
39 
46  public function registerTaxRate(TaxRateModel $taxRateModel)
47  {
48  $this->taxRateRegistryById[$taxRateModel->getId()] = $taxRateModel;
49  }
50 
58  public function retrieveTaxRate($taxRateId)
59  {
60  if (isset($this->taxRateRegistryById[$taxRateId])) {
61  return $this->taxRateRegistryById[$taxRateId];
62  }
64  $taxRateModel = $this->taxRateModelFactory->create()->load($taxRateId);
65  if (!$taxRateModel->getId()) {
66  // tax rate does not exist
67  throw NoSuchEntityException::singleField('taxRateId', $taxRateId);
68  }
69  $this->taxRateRegistryById[$taxRateModel->getId()] = $taxRateModel;
70  return $taxRateModel;
71  }
72 
79  public function removeTaxRate($taxRateId)
80  {
81  unset($this->taxRateRegistryById[$taxRateId]);
82  }
83 }
registerTaxRate(TaxRateModel $taxRateModel)
__construct(TaxRateModelFactory $taxModelRateFactory)