Skip to content

Commit

Permalink
Merge pull request #586 from bummzack/fix-globaltaxmodifier
Browse files Browse the repository at this point in the history
Merge #586
  • Loading branch information
bummzack authored Feb 20, 2017
2 parents 3cf6013 + 46d6a5e commit d677eb1
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions code/modifiers/tax/GlobalTaxModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,42 @@ public function value($incoming)

public function Rate()
{
// If the order is no longer in cart, rely on the saved data
if ($this->OrderID && !$this->Order()->IsCart()){
return $this->getField('Rate');
}

$rates = self::config()->country_rates;
if (isset($rates[$this->Country])) {
return $this->Rate = $rates[$this->Country]['rate'];
$country = $this->Country();
if ($country && isset($rates[$country])) {
return $this->Rate = $rates[$country]['rate'];
}
$defaults = self::config()->defaults;
return $this->Rate = $defaults['Rate'];
}

public function TableTitle()
{
$country = $this->Country ? " for " . $this->Country . " " : "";
$country = $this->Country() ? ' (' . $this->Country() . ') ' : '';
return parent::TableTitle() . $country .
($this->Type == "Chargable" ? '' : _t("GlobalTaxModifier.Included", ' (included in the above price)'));
($this->Type == "Chargable" ? '' : _t("GlobalTaxModifier.Included", ' (included in the above price)'));
}

public function Country()
{
if ($this->OrderID && $address = $this->Order()->getBillingAddress()) {
return $address->Country;
}

return null;
}

public function onBeforeWrite()
{
parent::onBeforeWrite();
// While the order is still in "Cart" status, persist country code to DB
if ($this->OrderID && $this->Order()->IsCart()){
$this->setField('Country', $this->Country());
}
}
}

0 comments on commit d677eb1

Please sign in to comment.