Skip to content

Commit

Permalink
Merge branch 'release/2.5.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
joshangell committed Jan 5, 2021
2 parents 41e0798 + c50479c commit 7b7e292
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## Unreleased

## 2.5.5 - 2021-01-05

### Fixed
- Fixed an issue introduced in 2.5.4 where order level discounts would also include line item level discounts, now they don’t


## 2.5.4 - 2020-09-15

### Fixed
Expand Down
11 changes: 8 additions & 3 deletions src/services/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public function registerSale(int $orderId) {
];

// Process the line items
$totalLineItemsDiscount = 0;
foreach ($lineItems as $lineItem) {

/** @var Variant $variant */
Expand All @@ -240,6 +241,9 @@ public function registerSale(int $orderId) {
// Get the per item discount amount - this will be negative, because getDiscount() returns a negative number
$perItemDiscount = bcdiv($lineItem->getDiscount(), $lineItem->qty, 5);

// Add it to our tracker, because its negative we just minus it here so we end up with a positive number
$totalLineItemsDiscount -= $lineItem->getDiscount();

// We can get the discounted item price (with tax) by adding the discount to the sale price
$itemPriceWithTax = bcadd($lineItem->salePrice, $perItemDiscount, 5);

Expand Down Expand Up @@ -309,13 +313,14 @@ public function registerSale(int $orderId) {
}
}

// Process order level discount adjustments
// Process order level discount adjustments - this does not include line item discounts
$totalDiscount = abs($order->getTotalDiscount());
if ($totalDiscount > 0) {
$orderDiscount = $totalDiscount - $totalLineItemsDiscount;
if ($orderDiscount > 0) {
$data['register_sale_products'][] = [
'product_id' => $settings->vend_discountProductId,
'quantity' => -1,
'price' => $totalDiscount,
'price' => $orderDiscount,
'price_set' => 1,
'tax' => 0,
'tax_id' => $settings->vend_noTaxId
Expand Down

0 comments on commit 7b7e292

Please sign in to comment.