I have created an order programatically in Magento 2.
I am provided with data:
- Item value: $10
- Tax Rate: 20%
- Discount: $2
- Grand Total: $10
Now taxes are inclusive product prices, so by default in Magento 2:
- Item price: $10
- Item price after discount: $8
- Tax: 20 % of $8 = $1.6
- Grand Total : $8 + $1.6 = $9.6.
Grand total is not same as provided.
I want to add discount after tax calculation.
2
Answers
For Tax configuration, there are two ways to fix this.
In backend configuration:
Apply Customer Tax ->set ‘Before Discount’; This should fix your problem I guess.
You can customize the code as well for same :
In your di.xml, add as below:
Now create your class file Tax.php and add below code:
Hope this helps!
Yes you can…. You can use default FPT and can modify tax amount as per your need.
you can use sales_quote_collect_totals_after event to change product tax amount programmatically.
This answer you can also try inside above overrided Tax model , it works fine.