Permalink
Browse files

Minor tax calculation fix

  • Loading branch information...
1 parent e4b1d1d commit bc20558b7db82d04f77dc0b895fe8d184afba9e8 @integry committed Oct 22, 2011
Showing with 25 additions and 16 deletions.
  1. +25 −16 application/model/order/CustomerOrder.php
View
41 application/model/order/CustomerOrder.php
@@ -1216,7 +1216,7 @@ public function hasCoupon($code)
private function getTaxes()
{
- $this->taxes = array();
+ $this->taxes = $this->taxDetails = array();
if ($this->shipments)
{
@@ -1648,6 +1648,8 @@ public function toArray($options = array())
}
}
+ $array['taxAmount'] = $taxAmount[$id];
+
foreach ($this->taxDetails as &$taxRate)
{
$taxRate['formattedAmount'] = $currency->getFormattedPrice($taxRate['amount']);
@@ -1680,21 +1682,6 @@ public function toArray($options = array())
$array['isAwaitingShipment'] = (int)$this->isAwaitingShipment();
$array['isProcessing'] = (int)$this->isProcessing();
- // discounts
- $array['discountAmount'] = 0;
- foreach (array_merge($this->fixedDiscounts, $this->orderDiscounts) as $key => $discount)
- {
- $array['discounts'][$discount->getID() ? $discount->getID() : $key] = $discount->toArray();
- $array['discountAmount'] -= $discount->amount->get();
- }
- $array['formatted_discountAmount'] = $this->getCurrency()->getFormattedPrice($array['discountAmount']);
-
- // coupons
- if (!is_null($this->coupons))
- {
- $array['coupons'] = $this->coupons->toArray();
- }
-
// payments
if (isset($options['payments']))
{
@@ -1751,6 +1738,28 @@ public function toArray($options = array())
}
}
+ // discounts
+ $array['discountAmount'] = 0;
+ foreach (array_merge($this->fixedDiscounts, $this->orderDiscounts) as $key => $discount)
+ {
+ $array['discounts'][$discount->getID() ? $discount->getID() : $key] = $discount->toArray();
+ $array['discountAmount'] -= $discount->amount->get();
+ }
+
+ // percentage discount applied to finalized order
+ if (!$array['discountAmount'] && $array['isFinalized'] && ($array['subtotalBeforeTaxes'] > $array['totalAmount']))
+ {
+ $array['discountAmount'] = $array['totalAmount'] - $array['subtotalBeforeTaxes'] - $array['taxAmount'];
+ }
+
+ $array['formatted_discountAmount'] = $this->getCurrency()->getFormattedPrice($array['discountAmount']);
+
+ // coupons
+ if (!is_null($this->coupons))
+ {
+ $array['coupons'] = $this->coupons->toArray();
+ }
+
if (!$array['isFinalized'])
{
//$this->isRulesProcessed = false;

0 comments on commit bc20558

Please sign in to comment.