Skip to content

Commit

Permalink
Tax calculation listener fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed Mar 4, 2024
1 parent 9fce6f1 commit 92ca08a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Foundation/Listeners/CalculateTaxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Vanilo\Adjustments\Contracts\Adjustable;
use Vanilo\Adjustments\Contracts\Adjustment;
use Vanilo\Adjustments\Models\AdjustmentTypeProxy;
use Vanilo\Cart\CartManager;
use Vanilo\Cart\Contracts\CartEvent;
use Vanilo\Checkout\Contracts\CheckoutEvent;
use Vanilo\Checkout\Facades\Checkout;
Expand All @@ -43,17 +44,19 @@ public function handle(CheckoutEvent|CartEvent $event): void
$checkout = Checkout::getFacadeRoot();
}

if (!$cart instanceof Adjustable) {
$cartModel = $cart instanceof CartManager ? $cart->model() : $cart;

if (!$cartModel instanceof Adjustable) {
return;
}

$cart->adjustments()->deleteByType(AdjustmentTypeProxy::TAX());
$cart->getItems()->each(fn ($item) => $item->adjustments()->deleteByType(AdjustmentTypeProxy::TAX()));

if (null !== $this->taxEngine) {
$taxes = [];
/** @var CartItem $item */
foreach ($cart->getItems() as $item) {
if ($rate = $this->taxEngine->findTaxRate($item)) {
if ($rate = $this->taxEngine->findTaxRate($item, $checkout->getBillpayer()->getBillingAddress(), $checkout->getShippingAddress())) {
$calculator = $rate->getCalculator();
if ($adjuster = $calculator->getAdjuster($rate->configuration())) {
//@todo the tax engine should tell whether to apply the tax to individual items (eg EU VAT)
Expand Down

0 comments on commit 92ca08a

Please sign in to comment.