From 3ac25cf746b7a5189a1bc8db8ad03bba50d3a42e Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Mon, 14 Dec 2020 13:33:25 +0530 Subject: [PATCH] Tax On Shipping Price Also --- packages/Webkul/Checkout/src/Cart.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index 43d3974f7..9a3d801a4 100755 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -558,14 +558,6 @@ class Cart $cart->grand_total = $cart->sub_total + $cart->tax_total - $cart->discount_amount; $cart->base_grand_total = $cart->base_sub_total + $cart->base_tax_total - $cart->base_discount_amount; - if ($shipping = $cart->selected_shipping_rate) { - $cart->grand_total = (float)$cart->grand_total + $shipping->price - $shipping->discount_amount; - $cart->base_grand_total = (float)$cart->base_grand_total + $shipping->base_price - $shipping->base_discount_amount; - - $cart->discount_amount += $shipping->discount_amount; - $cart->base_discount_amount += $shipping->base_discount_amount; - } - $cart = $this->finalizeCartTotals($cart); $quantities = 0; @@ -577,7 +569,7 @@ class Cart $cart->items_count = $cart->items->count(); $cart->items_qty = $quantities; - + $cart->cart_currency_code = core()->getCurrentCurrencyCode(); $cart->save(); @@ -700,8 +692,18 @@ class Cart if ($haveTaxRate) { $item->tax_percent = $rate->tax_rate; - $item->tax_amount = round(($item->total * $rate->tax_rate) / 100, 4); - $item->base_tax_amount = round(($item->base_total * $rate->tax_rate) / 100, 4); + + /* getting shipping rate for tax calculation */ + $shippingPrice = $shippingBasePrice = 0; + + if ($shipping = $cart->selected_shipping_rate) { + $shippingPrice = $shipping->price - $shipping->discount_amount; + $shippingBasePrice = $shipping->base_price - $shipping->base_discount_amount; + } + + /* now assigning shipping prices for tax calculation */ + $item->tax_amount = round((($item->total + $shippingPrice) * $rate->tax_rate) / 100, 4); + $item->base_tax_amount = round((($item->base_total + $shippingBasePrice) * $rate->tax_rate) / 100, 4); break; }