Calculate unit_price based on qty
authorDavid Reedy Jr <davidrjr.konadave@gmail.com>
Tue, 17 May 2022 13:15:21 +0000 (08:15 -0500)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 24 May 2022 08:41:47 +0000 (20:41 +1200)
CRM/Financial/BAO/Order.php

index 63476d8749accb41a324fcaca39c2b589f5beb56..7374dce22293de79b7f13d1032c92531f0423ca7 100644 (file)
@@ -1036,10 +1036,16 @@ class CRM_Financial_BAO_Order {
     if ($taxRate) {
       // Total is tax inclusive.
       $lineItem['tax_amount'] = ($taxRate / 100) * $this->getOverrideTotalAmount() / (1 + ($taxRate / 100));
-      $lineItem['line_total'] = $lineItem['unit_price'] = $this->getOverrideTotalAmount() - $lineItem['tax_amount'];
+      $lineItem['line_total'] = $this->getOverrideTotalAmount() - $lineItem['tax_amount'];
     }
     else {
-      $lineItem['line_total'] = $lineItem['unit_price'] = $this->getOverrideTotalAmount();
+      $lineItem['line_total'] = $this->getOverrideTotalAmount();
+    }
+    if (!empty($lineItem['qty'])) {
+      $lineItem['unit_price'] = $lineItem['line_total'] / $lineItem['qty'];
+    }
+    else {
+      $lineItem['unit_price'] = $lineItem['line_total'];
     }
   }