cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 Issue With Order Total If add custom amount to Tax

Magento 2 Issue With Order Total If add custom amount to Tax

I am adding custom amount to tax using Observer. My Observer code in events.xml is

 

<event name="sales_quote_address_collect_totals_after">
    <observer name="addtax" instance="Vendor\Mymodule\Observer\ChangeTaxTotal"/>
</event>

My Observer file code to add custom amount to tax is

if (count($total->getAppliedTaxes()) > 0) {
            $total->addTotalAmount('tax', $percentfval);
            $total->setGrandTotal($total->getGrandTotal() + $percentfval);
        }

It is working fine. But the issue when i use Gift Card. After applying gift card my order total should be 0. Because it is lesser than the gift card balance. But the Order Total remains the $percentfval value that i have added in here

$total->setGrandTotal($total->getGrandTotal() + $percentfval);

the balance amount remain $percentfval. I think i am making mistake while adding $percentfval amount to order final total.