Skip to content

Commit

Permalink
Update CalculateTax.php (#905)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecritson authored Mar 29, 2023
1 parent a25ae05 commit 48e1820
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/core/src/Pipelines/Cart/CalculateTax.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CalculateTax
*/
public function handle(Cart $cart, Closure $next)
{
$taxBreakDown = new TaxBreakdown;
$taxBreakDownAmounts = collect();

foreach ($cart->lines as $cartLine) {
$subTotal = $cartLine->subTotal?->value;
Expand All @@ -28,26 +28,33 @@ public function handle(Cart $cart, Closure $next)
$subTotal = $cartLine->subTotalDiscounted?->value;
}

$taxBreakDown = Taxes::setShippingAddress($cart->shippingAddress)
$taxBreakDownResult = Taxes::setShippingAddress($cart->shippingAddress)
->setBillingAddress($cart->billingAddress)
->setCurrency($cart->currency)
->setPurchasable($cartLine->purchasable)
->setCartLine($cartLine)
->getBreakdown($subTotal);

$taxTotal = $taxBreakDown->amounts->sum('price.value');
$taxBreakDownAmounts = $taxBreakDownAmounts->merge(
$taxBreakDownResult->amounts
);

$cartLine->taxBreakdown = $taxBreakDown;
$taxTotal = $taxBreakDownResult->amounts->sum('price.value');

$cartLine->taxBreakdown = $taxBreakDownResult;

$cart->taxTotal = new Price($taxTotal, $cart->currency, 1);
$cartLine->taxAmount = new Price($taxTotal, $cart->currency, $unitQuantity);
$cartLine->total = new Price($subTotal + $taxTotal, $cart->currency, $unitQuantity);
}

$taxBreakDown = new TaxBreakdown($taxBreakDownAmounts);

$taxTotal = $cart->lines->sum('taxAmount.value');
$taxBreakDownAmounts = $taxBreakDown->amounts->filter()->flatten();

if ($shippingAddress = $cart->shippingAddress) {

$taxTotal += $shippingAddress->shippingTaxTotal?->value;
$shippingTaxBreakdown = $shippingAddress->taxBreakdown;

Expand Down

0 comments on commit 48e1820

Please sign in to comment.