Skip to content

Commit

Permalink
Update SalesTaxService.php
Browse files Browse the repository at this point in the history
Makes sure discounts for specific line items take in any Avatax Tax Code overrides that may be present for that line item.
  • Loading branch information
mildlygeeky committed Apr 23, 2019
1 parent 2c6e9cf commit 7b12b9e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/services/SalesTaxService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use craft\commerce\Plugin as Commerce;
use craft\commerce\models\Address;
use craft\commerce\models\OrderAdjustment;
use craft\commerce\models\Transaction;
use craft\commerce\elements\Order;
use craft\commerce\helpers\Currency;
Expand Down Expand Up @@ -546,7 +547,24 @@ private function getTotalTax($order, $transaction)

foreach ($order->adjustments as $adjustment) {

/** @var OrderAdjustment $adjustment */

if($adjustment->type === 'discount') {

// if the discount is for a specific lineItem
if ($adjustmentLineItem = $adjustment->getLineItem()) {

// check to see if there is an Avatax Tax Code override specified
if(isset($adjustmentLineItem->purchasable->product->avataxTaxCode)) {

// if so, use this as the discountCode to make sure the adjustment is applied
// only to lineItems with that same tax code
$discountCode = $adjustmentLineItem->purchasable->product->avataxTaxCode;

}

}

$t = $t->withLine(
$adjustment->amount, // Total amount for the line item
1, // quantity
Expand Down

0 comments on commit 7b12b9e

Please sign in to comment.