Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TaxRuleRegistry.php
Go to the documentation of this file.
1 <?php
8 
11 use Magento\Tax\Model\Calculation\RuleFactory as TaxRuleModelFactory;
12 
14 {
18  private $taxRuleModelFactory;
19 
23  private $registry = [];
24 
30  public function __construct(
31  TaxRuleModelFactory $taxRuleModelFactory
32  ) {
33  $this->taxRuleModelFactory = $taxRuleModelFactory;
34  }
35 
42  public function registerTaxRule(TaxRuleModel $taxRuleModel)
43  {
44  $this->registry[$taxRuleModel->getId()] = $taxRuleModel;
45  }
46 
54  public function retrieveTaxRule($taxRuleId)
55  {
56  if (isset($this->registry[$taxRuleId])) {
57  return $this->registry[$taxRuleId];
58  }
59  $taxRuleModel = $this->taxRuleModelFactory->create()->load($taxRuleId);
60  if (!$taxRuleModel->getId()) {
61  // tax rule does not exist
62  throw NoSuchEntityException::singleField('taxRuleId', $taxRuleId);
63  }
64  $this->registry[$taxRuleModel->getId()] = $taxRuleModel;
65  return $taxRuleModel;
66  }
67 
74  public function removeTaxRule($taxRuleId)
75  {
76  unset($this->registry[$taxRuleId]);
77  }
78 }
__construct(TaxRuleModelFactory $taxRuleModelFactory)