Skip to content

Commit

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

## Unreleased

## 2.5.6 - 2021-03-11

### Fixed
- Fixed an issue where order level discounts weren’t showing the tax inside them

## 2.5.5 - 2021-01-05

### Fixed
Expand Down
14 changes: 13 additions & 1 deletion src/controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ public function actionSave(): Response
$settings->vend_discountProductId = $request->getBodyParam('vend_discountProductId') ?? $settings->vend_discountProductId;
$settings->vend_noTaxId = $request->getBodyParam('vend_noTaxId') ?? $settings->vend_noTaxId;

// If we have a discount product (which we should) then we need to fetch the tax info
if ($settings->vend_discountProductId) {

// Get the discount product from the API again
$discountProductResponse = Vend::$plugin->api->getResponse('products/'.$settings->vend_discountProductId);
if ($discountProductResponse && isset($discountProductResponse['products'])) {
$discountProduct = $discountProductResponse['products'][0];
$settings->vend_discountTaxId = $discountProduct['tax_id'];
$settings->vend_discountTaxRate = $discountProduct['tax_rate'];
}
}

if (!$settings->validate()) {
Craft::$app->getSession()->setError(Craft::t('vend', 'Couldn’t save settings.'));
return $this->renderTemplate('vend/settings/general', compact('settings'));
Expand Down Expand Up @@ -583,4 +595,4 @@ public function actionFeedMe(): Response
return $this->renderTemplate('vend/settings/feedme', $variables);
}

}
}
10 changes: 10 additions & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ class Settings extends Model
*/
public $vend_discountProductId;

/**
* @var string
*/
public $vend_discountTaxId;

/**
* @var string
*/
public $vend_discountTaxRate;

/**
* @var string
*/
Expand Down
11 changes: 8 additions & 3 deletions src/services/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,18 @@ public function registerSale(int $orderId) {
$totalDiscount = abs($order->getTotalDiscount());
$orderDiscount = $totalDiscount - $totalLineItemsDiscount;
if ($orderDiscount > 0) {

// Process the special discount product tax rate
$orderDiscountTaxAmount = bcmul($orderDiscount, $settings->vend_discountTaxRate, 5);
$orderDiscountWithoutTax = bcsub($orderDiscount, $orderDiscountTaxAmount, 5);

$data['register_sale_products'][] = [
'product_id' => $settings->vend_discountProductId,
'quantity' => -1,
'price' => $orderDiscount,
'price' => $orderDiscountWithoutTax,
'price_set' => 1,
'tax' => 0,
'tax_id' => $settings->vend_noTaxId
'tax' => $orderDiscountTaxAmount,
'tax_id' => $settings->vend_discountTaxId
];
}

Expand Down

0 comments on commit dddc9f7

Please sign in to comment.