Skip to content
This repository
Browse code

Minor tax calculation fix

  • Loading branch information...
commit bc20558b7db82d04f77dc0b895fe8d184afba9e8 1 parent e4b1d1d
Rinalds Uzkalns authored

Showing 1 changed file with 25 additions and 16 deletions. Show diff stats Hide diff stats

  1. +25 16 application/model/order/CustomerOrder.php
41 application/model/order/CustomerOrder.php
@@ -1216,7 +1216,7 @@ public function hasCoupon($code)
1216 1216
1217 1217 private function getTaxes()
1218 1218 {
1219   - $this->taxes = array();
  1219 + $this->taxes = $this->taxDetails = array();
1220 1220
1221 1221 if ($this->shipments)
1222 1222 {
@@ -1648,6 +1648,8 @@ public function toArray($options = array())
1648 1648 }
1649 1649 }
1650 1650
  1651 + $array['taxAmount'] = $taxAmount[$id];
  1652 +
1651 1653 foreach ($this->taxDetails as &$taxRate)
1652 1654 {
1653 1655 $taxRate['formattedAmount'] = $currency->getFormattedPrice($taxRate['amount']);
@@ -1680,21 +1682,6 @@ public function toArray($options = array())
1680 1682 $array['isAwaitingShipment'] = (int)$this->isAwaitingShipment();
1681 1683 $array['isProcessing'] = (int)$this->isProcessing();
1682 1684
1683   - // discounts
1684   - $array['discountAmount'] = 0;
1685   - foreach (array_merge($this->fixedDiscounts, $this->orderDiscounts) as $key => $discount)
1686   - {
1687   - $array['discounts'][$discount->getID() ? $discount->getID() : $key] = $discount->toArray();
1688   - $array['discountAmount'] -= $discount->amount->get();
1689   - }
1690   - $array['formatted_discountAmount'] = $this->getCurrency()->getFormattedPrice($array['discountAmount']);
1691   -
1692   - // coupons
1693   - if (!is_null($this->coupons))
1694   - {
1695   - $array['coupons'] = $this->coupons->toArray();
1696   - }
1697   -
1698 1685 // payments
1699 1686 if (isset($options['payments']))
1700 1687 {
@@ -1751,6 +1738,28 @@ public function toArray($options = array())
1751 1738 }
1752 1739 }
1753 1740
  1741 + // discounts
  1742 + $array['discountAmount'] = 0;
  1743 + foreach (array_merge($this->fixedDiscounts, $this->orderDiscounts) as $key => $discount)
  1744 + {
  1745 + $array['discounts'][$discount->getID() ? $discount->getID() : $key] = $discount->toArray();
  1746 + $array['discountAmount'] -= $discount->amount->get();
  1747 + }
  1748 +
  1749 + // percentage discount applied to finalized order
  1750 + if (!$array['discountAmount'] && $array['isFinalized'] && ($array['subtotalBeforeTaxes'] > $array['totalAmount']))
  1751 + {
  1752 + $array['discountAmount'] = $array['totalAmount'] - $array['subtotalBeforeTaxes'] - $array['taxAmount'];
  1753 + }
  1754 +
  1755 + $array['formatted_discountAmount'] = $this->getCurrency()->getFormattedPrice($array['discountAmount']);
  1756 +
  1757 + // coupons
  1758 + if (!is_null($this->coupons))
  1759 + {
  1760 + $array['coupons'] = $this->coupons->toArray();
  1761 + }
  1762 +
1754 1763 if (!$array['isFinalized'])
1755 1764 {
1756 1765 //$this->isRulesProcessed = false;

0 comments on commit bc20558

Please sign in to comment.
Something went wrong with that request. Please try again.