Skip to content

Commit

Permalink
Tax calculation fix (in amount details)
Browse files Browse the repository at this point in the history
- Added the `itemsPreAdjustmentTotal()` method to the Foundation's adjustable Cart model
  • Loading branch information
fulopattila122 committed Apr 4, 2024
1 parent 1025f85 commit a4a4b5c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
- Added the `Address` DTO class (implements the `Address` interface)
- Added the `AdjusterAliases` class that for decoupling FQCNs from the database
- Added automatic mapping of adjuster FQCN <-> aliases when saving an adjustment into the DB and when calling the `getAdjuster()` method
- Added the `itemsPreAdjustmentTotal()` method to the Foundation's adjustable Cart model
- BC: Added the `findBySku()` method to the `Product` and `MasterProductVariant` interfaces
- BC: The `MasterProduct` interface no longer extends the `Product` interface
- BC: The `Checkout` interface now extends the `ArrayAccess` and the `Shippable` interfaces (until here, only the concrete classes have implementation it)
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/Listeners/CalculateTaxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function handle(CheckoutEvent|CartEvent $event): void

$checkout->setTaxesAmount(
DetailedAmount::fromArray(
Arr::mapWithKeys($taxes, fn ($amount, $title) => [['title' => $title, 'amount' => $amount]]),
collect($taxes)->map(fn ($amount, $title) => ['title' => $title, 'amount' => $amount])->values()->all(),
),
);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Foundation/Models/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public function itemsTotal(): float
return $this->items->sum('total');
}

public function itemsPreAdjustmentTotal(): float
{
return $this->items->sum(fn ($item) => $item->preAdjustmentTotal());
}

public function shippingAdjustmentsTotal(): float
{
return $this->adjustments()->byType(AdjustmentTypeProxy::SHIPPING())->total();
Expand Down

0 comments on commit a4a4b5c

Please sign in to comment.