public function load(Product $product, Country $country) { $this->product = null; $this->country = null; $this->taxRulesCollection = null; if ($product->getId() === null) { throw new TaxEngineException('Product id is empty in Calculator::load', TaxEngineException::UNDEFINED_PRODUCT); } if ($country->getId() === null) { throw new TaxEngineException('Country id is empty in Calculator::load', TaxEngineException::UNDEFINED_COUNTRY); } $this->product = $product; $this->country = $country; $this->taxRulesCollection = $this->taxRuleQuery->getTaxCalculatorCollection($product->getTaxRule(), $country); return $this; }
public function loadTaxRule(TaxRule $taxRule, Country $country, Product $product) { $this->product = null; $this->country = null; $this->taxRulesCollection = null; if ($taxRule->getId() === null) { throw new TaxEngineException('TaxRule id is empty in Calculator::loadTaxRule', TaxEngineException::UNDEFINED_TAX_RULE); } if ($country->getId() === null) { throw new TaxEngineException('Country id is empty in Calculator::loadTaxRule', TaxEngineException::UNDEFINED_COUNTRY); } if ($product->getId() === null) { throw new TaxEngineException('Product id is empty in Calculator::loadTaxRule', TaxEngineException::UNDEFINED_PRODUCT); } $this->country = $country; $this->product = $product; $key = $product->getTaxRule()->getId() . '-' . $country->getId(); if (!isset(self::$taxRulesMap[$key])) { self::$taxRulesMap[$key] = $this->taxRuleQuery->getTaxCalculatorCollection($taxRule, $country); } $this->taxRulesCollection = self::$taxRulesMap[$key]; return $this; }