I need to know how I get the tax rate of an order. Currently I'm calculation this value with
$order->getShippingTaxAmount() and $order->getShippingAmount()
It's really, really ugly, but this works so far. But if there are no shipping cost, I don't get the tax rate. I need the rate for an ERP-system to do other tasks.
I've tried to use "var_dump()" for the order object and looked for my value by searching the tax rate, but can't find anything. Another idea was "get_class_methods", but also no luck.
I know, there is another thread (#6940246), but the solution works "global" - I need the tax rate of a specific order, which depends on country or customer - and should be historical.
First, you need to configure the origin shipping method in Magento 2 to calculate the shipping costs for the shipments from your store and calculate the tax for your products. Go to Stores > Settings > Configuration > Sales > Delivery Methods (formerly Shipping Methods) and specify all the necessary details here.
Tax rate is a combination of tax zone (such as country, state or zip) and percentage. You can set up tax rates as shown in the following steps. Step 1 − Login to Magento Admin Panel. Step 2 − Go to Sales menu → Tax and click on the Manage Tax Zones & Rates option.
You can use $tax_info = $order->getFullTaxInfo();
This method comes directly from the order Model. It will give you an array containing detailed tax information for that order, including amount, tax code, title, tax id, percent.
To recieve e.g. the tax rate in percent, you can then use $tax_rate = $tax_info[0]['percent'];
If you are in the 'quote' situation.
$store = $quote->getStore()
$taxCalculation = Mage::getModel('tax/calculation');
$request = $taxCalculation->getRateRequest(null, null, null, $store);
$taxRateId = Mage::getStoreConfig('tax/classes/shipping_tax_class', $store);
//taxRateId is the same model id as product tax classes, so you can do this:
$percent = $taxCalculation->getRate($request->setProductClassId($taxRateId));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With