Skip to content
Permalink
Browse files

Allow to load tax rule without country

  • Loading branch information...
lopes-vincent committed Mar 6, 2019
1 parent 00856b7 commit c97897d2dc46e3cd26ecb9944a80b654b542185e
Showing with 28 additions and 7 deletions.
  1. +9 −7 core/lib/Thelia/Model/TaxRuleQuery.php
  2. +19 −0 core/lib/Thelia/TaxEngine/Calculator.php
@@ -28,30 +28,32 @@ class TaxRuleQuery extends BaseTaxRuleQuery
*
* @return array|mixed|\Propel\Runtime\Collection\ObjectCollection
*/
public function getTaxCalculatorCollection(TaxRule $taxRule, Country $country, State $state = null)
public function getTaxCalculatorCollection(TaxRule $taxRule, Country $country = null, State $state = null)
{
$key = sprintf(
'%s-%s-%s',
$taxRule->getId(),
$country->getId(),
($country !== null) ? $country->getId() : 0,
($state !== null) ? $state->getId() : 0
);
if (array_key_exists($key, self::$caches)) {
return self::$caches[$key];
}
$taxRuleQuery = TaxRuleCountryQuery::create()
->filterByCountry($country, Criteria::EQUAL)
->filterByTaxRuleId($taxRule->getId());
if (null !== $country) {
$taxRuleQuery->filterByCountry($country, Criteria::EQUAL);
}
if (null !== $state) {
$taxRuleCount = clone $taxRuleQuery;
$taxRuleCount->filterByStateId($state->getId(), Criteria::EQUAL)
->count();
->count();
if (0 === $taxRuleCount) {
$taxRuleQuery->filterByStateId(null, Criteria::EQUAL);
}
@@ -97,6 +97,25 @@ public function loadTaxRule(TaxRule $taxRule, Country $country, Product $product
return $this;
}
public function loadTaxRuleWithoutCountry(TaxRule $taxRule, Product $product)
{
$this->product = null;
$this->taxRulesCollection = null;
if ($taxRule->getId() === null) {
throw new TaxEngineException('TaxRule id is empty in Calculator::loadTaxRule', TaxEngineException::UNDEFINED_TAX_RULE);
}
if ($product->getId() === null) {
throw new TaxEngineException('Product id is empty in Calculator::load', TaxEngineException::UNDEFINED_PRODUCT);
}
$this->product = $product;
$this->taxRulesCollection = $this->taxRuleQuery->getTaxCalculatorCollection($taxRule);
return $this;
}
public function loadTaxRuleWithoutProduct(TaxRule $taxRule, Country $country, State $state = null)
{
$this->product = null;

0 comments on commit c97897d

Please sign in to comment.
You can’t perform that action at this time.